MCPcopy Index your code
hub / github.com/cpplint/cpplint / testDeprecatedCast

Method testDeprecatedCast

cpplint_unittest.py:1005–1068  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1003
1004 # Test deprecated casts such as int(d)
1005 def testDeprecatedCast(self):
1006 self.TestLint(
1007 "int a = int(2.2);",
1008 "Using deprecated casting style. "
1009 "Use static_cast<int>(...) instead"
1010 " [readability/casting] [4]",
1011 )
1012
1013 self.TestLint(
1014 '(char *) "foo"',
1015 "Using C-style cast. Use const_cast<char *>(...) instead [readability/casting] [4]",
1016 )
1017
1018 self.TestLint(
1019 "(int*)foo",
1020 "Using C-style cast. "
1021 "Use reinterpret_cast<int*>(...) instead"
1022 " [readability/casting] [4]",
1023 )
1024
1025 # Checks for false positives...
1026 self.TestLint("int a = int();", "") # constructor
1027 self.TestLint("X::X() : a(int()) {}", "") # default constructor
1028 self.TestLint("operator bool();", "") # Conversion operator
1029 self.TestLint("new int64_t(123);", "") # "new" operator on basic type
1030 self.TestLint("new int64_t(123);", "") # "new" operator on basic type
1031 self.TestLint("new const int(42);", "") # "new" on const-qualified type
1032 self.TestLint("using a = bool(int arg);", "") # C++11 alias-declaration
1033 self.TestLint("x = bit_cast<double(*)[3]>(y);", "") # array of array
1034 self.TestLint("void F(const char(&src)[N]);", "") # array of references
1035
1036 # Placement new
1037 self.TestLint("new(field_ptr) int(field->default_value_enum()->number());", "")
1038
1039 # C++11 function wrappers
1040 self.TestLint("std::function<int(bool)>", "")
1041 self.TestLint("std::function<const int(bool)>", "")
1042 self.TestLint("std::function< int(bool) >", "")
1043 self.TestLint("mfunction<int(bool)>", "")
1044
1045 error_collector = ErrorCollector(self.assertTrue)
1046 cpplint.ProcessFileData(
1047 "test.cc",
1048 "cc",
1049 [
1050 "// Copyright 2014 Your Company. All Rights Reserved.",
1051 "typedef std::function<",
1052 " bool(int)> F;",
1053 "",
1054 ],
1055 error_collector,
1056 )
1057 assert error_collector.Results() == ""
1058
1059 # Return types for function pointers
1060 self.TestLint("typedef bool(FunctionPointer)();", "")
1061 self.TestLint("typedef bool(FunctionPointer)(int param);", "")
1062 self.TestLint("typedef bool(MyClass::*MemberFunctionPointer)();", "")

Callers

nothing calls this directly

Calls 3

ResultsMethod · 0.95
ErrorCollectorClass · 0.85
TestLintMethod · 0.80

Tested by

no test coverage detected