(self)
| 803 | |
| 804 | # Test C-style cast cases. |
| 805 | def testCStyleCast(self): |
| 806 | self.TestLint( |
| 807 | "int a = (int)1.0;", |
| 808 | "Using C-style cast. Use static_cast<int>(...) instead [readability/casting] [4]", |
| 809 | ) |
| 810 | self.TestLint( |
| 811 | "int a = (int)-1.0;", |
| 812 | "Using C-style cast. Use static_cast<int>(...) instead [readability/casting] [4]", |
| 813 | ) |
| 814 | self.TestLint( |
| 815 | "int *a = (int *)NULL;", |
| 816 | "Using C-style cast. Use reinterpret_cast<int *>(...) instead" |
| 817 | " [readability/casting] [4]", |
| 818 | ) |
| 819 | |
| 820 | self.TestLint( |
| 821 | "uint16_t a = (uint16_t)1.0;", |
| 822 | "Using C-style cast. Use static_cast<uint16_t>(...) instead" |
| 823 | " [readability/casting] [4]", |
| 824 | ) |
| 825 | self.TestLint( |
| 826 | "int32_t a = (int32_t)1.0;", |
| 827 | "Using C-style cast. Use static_cast<int32_t>(...) instead [readability/casting] [4]", |
| 828 | ) |
| 829 | self.TestLint( |
| 830 | "uint64_t a = (uint64_t)1.0;", |
| 831 | "Using C-style cast. Use static_cast<uint64_t>(...) instead" |
| 832 | " [readability/casting] [4]", |
| 833 | ) |
| 834 | self.TestLint( |
| 835 | "size_t a = (size_t)1.0;", |
| 836 | "Using C-style cast. Use static_cast<size_t>(...) instead [readability/casting] [4]", |
| 837 | ) |
| 838 | |
| 839 | # These shouldn't be recognized casts. |
| 840 | self.TestLint("u a = (u)NULL;", "") |
| 841 | self.TestLint("uint a = (uint)NULL;", "") |
| 842 | self.TestLint("typedef MockCallback<int(int)> CallbackType;", "") |
| 843 | self.TestLint("scoped_ptr< MockCallback<int(int)> > callback_value;", "") |
| 844 | self.TestLint("std::function<int(bool)>", "") |
| 845 | self.TestLint("x = sizeof(int)", "") |
| 846 | self.TestLint("x = alignof(int)", "") |
| 847 | self.TestLint("alignas(int) char x[42]", "") |
| 848 | self.TestLint("alignas(alignof(x)) char y[42]", "") |
| 849 | self.TestLint("void F(int (func)(int));", "") |
| 850 | self.TestLint("void F(int (func)(int*));", "") |
| 851 | self.TestLint("void F(int (Class::member)(int));", "") |
| 852 | self.TestLint("void F(int (Class::member)(int*));", "") |
| 853 | self.TestLint("void F(int (Class::member)(int), int param);", "") |
| 854 | self.TestLint("void F(int (Class::member)(int*), int param);", "") |
| 855 | self.TestLint("X Class::operator++(int)", "") |
| 856 | self.TestLint("X Class::operator--(int)", "") |
| 857 | |
| 858 | # These should not be recognized (lambda functions without arg names). |
| 859 | self.TestLint("[](int/*unused*/) -> bool {", "") |
| 860 | self.TestLint("[](int /*unused*/) -> bool {", "") |
| 861 | self.TestLint("auto f = [](MyStruct* /*unused*/)->int {", "") |
| 862 | self.TestLint("[](int) -> bool {", "") |
nothing calls this directly
no test coverage detected