diff --git a/.gitignore b/.gitignore index e527734..712f99b 100644 --- a/.gitignore +++ b/.gitignore @@ -78,6 +78,9 @@ target/ profile_default/ ipython_config.py +# VSCode +.vscode/ + # pyenv .python-version diff --git a/cpplint_clitest.py b/cpplint_clitest.py index efcf7d2..b23449a 100755 --- a/cpplint_clitest.py +++ b/cpplint_clitest.py @@ -185,10 +185,7 @@ def testVlcSample(self): self.checkAllInFolder('./samples/vlc-sample', 1) def testSillySample(self): - self.checkAllInFolder('./samples/silly-sample', 4) - - def testCfgFileSample(self): - self.checkAllInFolder('./samples/cfg-file', 1) + self.checkAllInFolder('./samples/silly-sample', 5) def testBoostSample(self): self.checkAllInFolder('./samples/boost-sample', 4) diff --git a/samples/cfg-file/CPPLINT.cfg b/samples/cfg-file/CPPLINT.cfg deleted file mode 100644 index 555621d..0000000 --- a/samples/cfg-file/CPPLINT.cfg +++ /dev/null @@ -1,3 +0,0 @@ -set noparent -filter=-whitespace,-build/include_what_you_use -linelength=80 diff --git a/samples/cfg-file/src/sillycode.cpp b/samples/cfg-file/src/sillycode.cpp deleted file mode 100644 index 98d5d6b..0000000 --- a/samples/cfg-file/src/sillycode.cpp +++ /dev/null @@ -1,262 +0,0 @@ -#include - -#include - -#include -class Date { - // ... -public: - Month month() const; // do - int month(); // don't - // ... -}; - -void do_something(vector& v) -{ - string val; - cin >> val; - // ... - int index = 0; // bad - for (int i = 0; i < v.size(); ++i) - if (v[i] == val) { - index = i; - break; - } - // ... -} - -struct X { - char ch; - int i; - string s; - char ch2; - - X& operator=(const X& a); - X(const X&); -}; - -X waste(const char* p) -{ - if (p == nullptr) throw Nullptr_error{}; - int n = strlen(p); - auto buf = new char[n]; - if (buf == nullptr) throw Allocation_error{}; - for (int i = 0; i < n; ++i) buf[i] = p[i]; - // ... manipulate buffer ... - X x; - x.ch = 'a'; - x.s = string(n); // give x.s space for *ps - for (int i = 0; i < x.s.size(); ++i) x.s[i] = buf[i]; // copy buf into x.s - delete buf; - return x; -} - -void driver() -{ - X x = waste("Typical argument"); - // ... -} - -class X { // BAD - int i; - string s; - int j; -public: - X() :i{666}, s{"qqq"} { } // j is uninitialized - X(int ii) :i{ii} {} // s is "" and j is uninitialized - // ... -}; - -class X2 { - int i {666}; - string s {"qqq"}; - int j {0}; -public: - X2() = default; // all members are initialized to their defaults - X2(int ii) :i{ii} {} // s and j initialized to their defaults - // ... -}; - -class X3 { // BAD: inexplicit, argument passing overhead - int i; - string s; - int j; -public: - X3(int ii = 666, const string& ss = "qqq", int jj = 0) - :i{ii}, s{ss}, j{jj} { } // all members are initialized to their defaults - // ... -}; - - -class Foo { - string s; - int i; -public: - Foo& operator=(Foo&& a); - // ... -}; - -Foo& Foo::operator=(Foo&& a) // OK, but there is a cost -{ - if (this == &a) return *this; // this line is redundant - s = std::move(a.s); - i = a.i; - return *this; -} - -template -class Vector2 { - // ... - Vector2(Vector2&& a) { *this = a; } // just use the copy - Vector2& operator=(Vector2&& a) { *this = a; } // just use the copy - //... -public: - T* elem; - int sz; -}; - -void f2(N::X& a, N::X& b) -{ - swap(a,b); // calls N::swap -} - -void f3(N::X& a, N::X& b) -{ - using std::swap; // make std::swap available - swap(a,b); // calls N::swap if it exists, otherwise std::swap -} - - -// webcolors.h (third party header) -#define RED 0xFF0000 -#define GREEN 0x00FF00 -#define BLUE 0x0000FF - -// productinfo.h -// The following define product subtypes based on color -#define RED 0 -#define PURPLE 1 -#define BLUE 2 - -int webby = BLUE; // webby==2; probably not what was desired - -enum class Webcolor { red=0xFF0000, green=0x00FF00, blue=0x0000FF }; -enum class Productinfo { red=0, purple=1, blue=2 }; - -int webby = blue; // error: be specific -Webcolor webby = Webcolor::blue; - -enum Webcolor { red=0xFF0000, green=0x00FF00, blue=0x0000FF }; -enum Productinfo { red=0, purple=1, blue=2 }; - -int webby = blue; // error, ambiguous: be specific -Webcolor webby = Webcolor::blue; - -enum class Webcolor { red=0xFF0000, green=0x00FF00, blue=0x0000FF }; -enum class Productinfo { red=0, purple=1, blue=2 }; - -int webby = blue; // error: blue undefined in this scope -Webcolor webby = Webcolor::blue; - - -void sink(unique_ptr); // consumes the widget - -void sink(widget*); // just uses the widget - -void thinko(const unique_ptr&); // usually not what you want - -void reseat(unique_ptr&); // "will" or "might" reseat pointer - -constexpr int max = 8*1024; -int buf[max]; // OK, but suspicious: uninitialized -f.read(buf, max); - -constexpr int max = 8*1024; -int buf[max] = {0}; // better in some situations -f.read(buf, max); - -string s; // s is default initialized to "" -cin >> s; // s expands to hold the string - - -error_code ec; -Value v = [&] { - auto p = get_value(); // get_value() returns a pair - ec = p.first; - return p.second; -}(); - -Value v = [] { - auto p = get_value(); // get_value() returns a pair - if (p.first) throw Bad_value{p.first}; - return p.second; -}(); - -SomeLargeType var; // ugly CaMeLcAsEvArIaBlE - -if (cond) // some non-trivial condition - Set(&var); -else if (cond2 || !cond3) { - var = Set2(3.14); -} -else { - var = 0; - for (auto& e : something) - var += e; -} - -string var = [&]{ - if (!in) return ""; // default - string s; - for (char c : in >> c) - s += toupper(c); - return s; -}(); // note () - -void use(int n) -{ - switch (n) { // good - case 0: // ... - case 7: // ... - } -} - -int n = numeric_limits::max(); -int m = n + 1; // bad - -std::string s = "hello world"; -double* p = (double*)(&s); // BAD - -class base { public: virtual ~base() = 0; }; - -class derived1 : public base { }; - -class derived2 : public base { - std::string s; -public: - std::string get_s() { return s; } -}; - -derived1 d1; -base* p = &d1; // ok, implicit conversion to pointer to base is fine - -derived2* p2 = (derived2*)(p); // BAD, tries to treat d1 as a derived2, which it is not -cout << p2.get_s(); // tries to access d1's nonexistent string member, instead sees arbitrary bytes near d1 - -void f(const int& i) { - (int&)(i) = 42; // BAD -} - -static int i = 0; -static const int j = 0; - -f(i); // silent side effect -f(j); // undefined behavior - - -auto x = m*v1 + vv; // multiply m with v1 and add the result to vv - -int i; -for (i = 0; i < max; ++i); // bug waiting to happen -if (i == j) - return i; diff --git a/samples/silly-sample/.cpplint b/samples/silly-sample/.cpplint new file mode 100644 index 0000000..5164091 --- /dev/null +++ b/samples/silly-sample/.cpplint @@ -0,0 +1,3 @@ +set noparent +filter=-build/namespaces, -whitespace,+whitespace/line_length,-build/include_what_you_use +headers=w diff --git a/samples/silly-sample/CPPLINT.cfg b/samples/silly-sample/CPPLINT.cfg new file mode 100644 index 0000000..54bf08c --- /dev/null +++ b/samples/silly-sample/CPPLINT.cfg @@ -0,0 +1,3 @@ +set noparent +linelength=84 +headers=omg, w diff --git a/samples/cfg-file/simple.def b/samples/silly-sample/cfg.def similarity index 67% rename from samples/cfg-file/simple.def rename to samples/silly-sample/cfg.def index 85f618c..9e3b03e 100644 --- a/samples/cfg-file/simple.def +++ b/samples/silly-sample/cfg.def @@ -1,16 +1,20 @@ -src/*.cpp +--config=.cpplint src/* 1 -3 +4 Done processing src/sillycode.cpp -Total errors found: 18 +Done processing src/sillycode.w +Total errors found: 26 src/sillycode.cpp:0: No copyright message found. You should have a line: "Copyright [year] " [legal/copyright] [5] -src/sillycode.cpp:3: Found C system header after C++ system header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] +src/sillycode.cpp:2: is an unapproved C++11 header. [build/c++11] [5] +src/sillycode.cpp:3: Found C system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] +src/sillycode.cpp:4: Found C system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] src/sillycode.cpp:14: Is this a non-const reference? If so, make const or use a pointer: vector& v [runtime/references] [2] src/sillycode.cpp:40: If/else bodies with multiple statements require braces [readability/braces] [4] src/sillycode.cpp:66: Single-parameter constructors should be marked explicit. [runtime/explicit] [4] src/sillycode.cpp:76: Single-parameter constructors should be marked explicit. [runtime/explicit] [4] src/sillycode.cpp:85: Constructors callable with one argument should be marked explicit. [runtime/explicit] [4] +src/sillycode.cpp:86: Lines should be <= 80 characters long [whitespace/line_length] [2] src/sillycode.cpp:118: Is this a non-const reference? If so, make const or use a pointer: N::X& a [runtime/references] [2] src/sillycode.cpp:118: Is this a non-const reference? If so, make const or use a pointer: N::X& b [runtime/references] [2] src/sillycode.cpp:123: Is this a non-const reference? If so, make const or use a pointer: N::X& a [runtime/references] [2] @@ -21,5 +25,10 @@ src/sillycode.cpp:199: If an else has a brace on one side, it should have it on src/sillycode.cpp:208: Static/global string variables are not permitted. [runtime/string] [4] src/sillycode.cpp:227: Static/global string variables are not permitted. [runtime/string] [4] src/sillycode.cpp:228: Using C-style cast. Use reinterpret_cast(...) instead [readability/casting] [4] +src/sillycode.cpp:243: Lines should be <= 80 characters long [whitespace/line_length] [2] src/sillycode.cpp:243: Using C-style cast. Use reinterpret_cast(...) instead [readability/casting] [4] +src/sillycode.cpp:244: Lines should be <= 80 characters long [whitespace/line_length] [2] +src/sillycode.cpp:249: Lines should be <= 80 characters long [whitespace/line_length] [2] +src/sillycode.w:0: No copyright message found. You should have a line: "Copyright [year] " [legal/copyright] [5] +src/sillycode.w:0: No #ifndef header guard found, suggested CPP variable is: SAMPLES_SILLY_SAMPLE_SRC_SILLYCODE_W_ [build/header_guard] [5] diff --git a/samples/silly-sample/filters.def b/samples/silly-sample/filters.def index be4cfab..fcdfbaa 100644 --- a/samples/silly-sample/filters.def +++ b/samples/silly-sample/filters.def @@ -2,14 +2,18 @@ 1 7 Done processing src/sillycode.cpp -Category 'build' errors found: 1 +Category 'build' errors found: 5 Category 'legal' errors found: 1 Category 'readability' errors found: 4 Category 'runtime' errors found: 12 -Total errors found: 18 +Total errors found: 22 src/sillycode.cpp:0: No copyright message found. You should have a line: "Copyright [year] " [legal/copyright] [5] -src/sillycode.cpp:3: Found C system header after C++ system header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] +src/sillycode.cpp:1: Include the directory when naming header files [build/include_subdir] [4] +src/sillycode.cpp:2: is an unapproved C++11 header. [build/c++11] [5] +src/sillycode.cpp:3: Found C system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] +src/sillycode.cpp:4: Found C system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] +src/sillycode.cpp:5: Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5] src/sillycode.cpp:14: Is this a non-const reference? If so, make const or use a pointer: vector& v [runtime/references] [2] src/sillycode.cpp:40: If/else bodies with multiple statements require braces [readability/braces] [4] src/sillycode.cpp:66: Single-parameter constructors should be marked explicit. [runtime/explicit] [4] diff --git a/samples/silly-sample/includeorder_cfirst.def b/samples/silly-sample/includeorder_cfirst.def index b8483cd..84a3af5 100644 --- a/samples/silly-sample/includeorder_cfirst.def +++ b/samples/silly-sample/includeorder_cfirst.def @@ -2,9 +2,16 @@ 1 3 Done processing src/sillycode.cpp -Total errors found: 110 +Total errors found: 123 src/sillycode.cpp:0: No copyright message found. You should have a line: "Copyright [year] " [legal/copyright] [5] +src/sillycode.cpp:1: Include the directory when naming header files [build/include_subdir] [4] +src/sillycode.cpp:2: At least two spaces is best between code and comments [whitespace/comments] [2] +src/sillycode.cpp:2: Should have a space between // and comment [whitespace/comments] [4] +src/sillycode.cpp:2: is an unapproved C++11 header. [build/c++11] [5] +src/sillycode.cpp:3: Found other system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] +src/sillycode.cpp:4: Found other system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] +src/sillycode.cpp:5: Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5] src/sillycode.cpp:8: public: should be indented +1 space inside class Date [whitespace/indent] [3] src/sillycode.cpp:14: Is this a non-const reference? If so, make const or use a pointer: vector& v [runtime/references] [2] src/sillycode.cpp:15: { should almost always be at the end of the previous line [whitespace/braces] [4] @@ -30,7 +37,6 @@ src/sillycode.cpp:80: At least two spaces is best between code and comments [w src/sillycode.cpp:84: public: should be indented +1 space inside class X3 [whitespace/indent] [3] src/sillycode.cpp:85: Constructors callable with one argument should be marked explicit. [runtime/explicit] [4] src/sillycode.cpp:86: Tab found; better to use spaces [whitespace/tab] [1] -src/sillycode.cpp:86: Lines should be <= 80 characters long [whitespace/line_length] [2] src/sillycode.cpp:94: public: should be indented +1 space inside class Foo [whitespace/indent] [3] src/sillycode.cpp:100: { should almost always be at the end of the previous line [whitespace/braces] [4] src/sillycode.cpp:110: Tab found; better to use spaces [whitespace/tab] [1] @@ -98,20 +104,27 @@ src/sillycode.cpp:228: At least two spaces is best between code and comments [ src/sillycode.cpp:228: Using C-style cast. Use reinterpret_cast(...) instead [readability/casting] [4] src/sillycode.cpp:236: public: should be indented +1 space inside class derived2 [whitespace/indent] [3] src/sillycode.cpp:241: At least two spaces is best between code and comments [whitespace/comments] [2] -src/sillycode.cpp:243: Lines should be <= 80 characters long [whitespace/line_length] [2] +src/sillycode.cpp:243: Lines should be <= 84 characters long [whitespace/line_length] [2] src/sillycode.cpp:243: At least two spaces is best between code and comments [whitespace/comments] [2] src/sillycode.cpp:243: Using C-style cast. Use reinterpret_cast(...) instead [readability/casting] [4] -src/sillycode.cpp:244: Lines should be <= 80 characters long [whitespace/line_length] [2] +src/sillycode.cpp:244: Lines should be <= 84 characters long [whitespace/line_length] [2] src/sillycode.cpp:244: At least two spaces is best between code and comments [whitespace/comments] [2] +src/sillycode.cpp:249: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] +src/sillycode.cpp:249: Lines should be <= 84 characters long [whitespace/line_length] [2] +src/sillycode.cpp:249: At least two spaces is best between code and comments [whitespace/comments] [2] +src/sillycode.cpp:249: Missing space before { [whitespace/braces] [5] src/sillycode.cpp:253: At least two spaces is best between code and comments [whitespace/comments] [2] src/sillycode.cpp:254: At least two spaces is best between code and comments [whitespace/comments] [2] src/sillycode.cpp:257: Tab found; better to use spaces [whitespace/tab] [1] src/sillycode.cpp:257: At least two spaces is best between code and comments [whitespace/comments] [2] src/sillycode.cpp:260: Empty loop bodies should use {} or continue [whitespace/empty_loop_body] [5] src/sillycode.cpp:260: At least two spaces is best between code and comments [whitespace/comments] [2] +src/sillycode.cpp:263: Redundant blank line at the end of a code block should be deleted. [whitespace/blank_line] [3] +src/sillycode.cpp:14: Add #include for vector<> [build/include_what_you_use] [4] src/sillycode.cpp:126: Add #include for swap [build/include_what_you_use] [4] src/sillycode.cpp:168: Add #include for unique_ptr<> [build/include_what_you_use] [4] +src/sillycode.cpp:179: Add #include for cin [build/include_what_you_use] [4] src/sillycode.cpp:224: Add #include for numeric_limits<> [build/include_what_you_use] [4] src/sillycode.cpp:237: Add #include for string [build/include_what_you_use] [4] -src/sillycode.cpp:244: Add #include for cout [build/include_what_you_use] [4] +src/sillycode.cpp:264: Could not find a newline character at the end of the file. [whitespace/ending_newline] [5] diff --git a/samples/silly-sample/sed.def b/samples/silly-sample/sed.def index 6e394e9..e4a40cc 100644 --- a/samples/silly-sample/sed.def +++ b/samples/silly-sample/sed.def @@ -1,13 +1,21 @@ --output=sed src/*.cpp 1 -5 +8 +sed -i '2s/\/\//\/\/ /' src/sillycode.cpp # Should have a space between // and comment [whitespace/comments] [4] sed -i '120s/,\([^ ]\)/, \1/g' src/sillycode.cpp # Missing space after , [whitespace/comma] [3] sed -i '122s/\s*$//' src/sillycode.cpp # Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] sed -i '126s/,\([^ ]\)/, \1/g' src/sillycode.cpp # Missing space after , [whitespace/comma] [3] sed -i '208s/\([^ ]\){/\1 {/' src/sillycode.cpp # Missing space before { [whitespace/braces] [5] +sed -i '249s/\s*$//' src/sillycode.cpp # Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] +sed -i '249s/\([^ ]\){/\1 {/' src/sillycode.cpp # Missing space before { [whitespace/braces] [5] # src/sillycode.cpp:0: "No copyright message found. You should have a line: "Copyright [year] "" [legal/copyright] [5] -# src/sillycode.cpp:3: "Found C system header after C++ system header. Should be: sillycode.h, c system, c++ system, other." [build/include_order] [4] +# src/sillycode.cpp:1: "Include the directory when naming header files" [build/include_subdir] [4] +# src/sillycode.cpp:2: "At least two spaces is best between code and comments" [whitespace/comments] [2] +# src/sillycode.cpp:2: " is an unapproved C++11 header." [build/c++11] [5] +# src/sillycode.cpp:3: "Found C system header after other header. Should be: sillycode.h, c system, c++ system, other." [build/include_order] [4] +# src/sillycode.cpp:4: "Found C system header after other header. Should be: sillycode.h, c system, c++ system, other." [build/include_order] [4] +# src/sillycode.cpp:5: "Do not use namespace using-directives. Use using-declarations instead." [build/namespaces] [5] # src/sillycode.cpp:8: "public: should be indented +1 space inside class Date" [whitespace/indent] [3] # src/sillycode.cpp:14: "Is this a non-const reference? If so, make const or use a pointer: vector& v" [runtime/references] [2] # src/sillycode.cpp:15: "{ should almost always be at the end of the previous line" [whitespace/braces] [4] @@ -33,7 +41,6 @@ sed -i '208s/\([^ ]\){/\1 {/' src/sillycode.cpp # Missing space before { [white # src/sillycode.cpp:84: "public: should be indented +1 space inside class X3" [whitespace/indent] [3] # src/sillycode.cpp:85: "Constructors callable with one argument should be marked explicit." [runtime/explicit] [4] # src/sillycode.cpp:86: "Tab found; better to use spaces" [whitespace/tab] [1] -# src/sillycode.cpp:86: "Lines should be <= 80 characters long" [whitespace/line_length] [2] # src/sillycode.cpp:94: "public: should be indented +1 space inside class Foo" [whitespace/indent] [3] # src/sillycode.cpp:100: "{ should almost always be at the end of the previous line" [whitespace/braces] [4] # src/sillycode.cpp:110: "Tab found; better to use spaces" [whitespace/tab] [1] @@ -97,20 +104,25 @@ sed -i '208s/\([^ ]\){/\1 {/' src/sillycode.cpp # Missing space before { [white # src/sillycode.cpp:228: "Using C-style cast. Use reinterpret_cast(...) instead" [readability/casting] [4] # src/sillycode.cpp:236: "public: should be indented +1 space inside class derived2" [whitespace/indent] [3] # src/sillycode.cpp:241: "At least two spaces is best between code and comments" [whitespace/comments] [2] -# src/sillycode.cpp:243: "Lines should be <= 80 characters long" [whitespace/line_length] [2] +# src/sillycode.cpp:243: "Lines should be <= 84 characters long" [whitespace/line_length] [2] # src/sillycode.cpp:243: "At least two spaces is best between code and comments" [whitespace/comments] [2] # src/sillycode.cpp:243: "Using C-style cast. Use reinterpret_cast(...) instead" [readability/casting] [4] -# src/sillycode.cpp:244: "Lines should be <= 80 characters long" [whitespace/line_length] [2] +# src/sillycode.cpp:244: "Lines should be <= 84 characters long" [whitespace/line_length] [2] # src/sillycode.cpp:244: "At least two spaces is best between code and comments" [whitespace/comments] [2] +# src/sillycode.cpp:249: "Lines should be <= 84 characters long" [whitespace/line_length] [2] +# src/sillycode.cpp:249: "At least two spaces is best between code and comments" [whitespace/comments] [2] # src/sillycode.cpp:253: "At least two spaces is best between code and comments" [whitespace/comments] [2] # src/sillycode.cpp:254: "At least two spaces is best between code and comments" [whitespace/comments] [2] # src/sillycode.cpp:257: "Tab found; better to use spaces" [whitespace/tab] [1] # src/sillycode.cpp:257: "At least two spaces is best between code and comments" [whitespace/comments] [2] # src/sillycode.cpp:260: "Empty loop bodies should use {} or continue" [whitespace/empty_loop_body] [5] # src/sillycode.cpp:260: "At least two spaces is best between code and comments" [whitespace/comments] [2] +# src/sillycode.cpp:263: "Redundant blank line at the end of a code block should be deleted." [whitespace/blank_line] [3] +# src/sillycode.cpp:14: "Add #include for vector<>" [build/include_what_you_use] [4] # src/sillycode.cpp:126: "Add #include for swap" [build/include_what_you_use] [4] # src/sillycode.cpp:168: "Add #include for unique_ptr<>" [build/include_what_you_use] [4] +# src/sillycode.cpp:179: "Add #include for cin" [build/include_what_you_use] [4] # src/sillycode.cpp:224: "Add #include for numeric_limits<>" [build/include_what_you_use] [4] # src/sillycode.cpp:237: "Add #include for string" [build/include_what_you_use] [4] -# src/sillycode.cpp:244: "Add #include for cout" [build/include_what_you_use] [4] +# src/sillycode.cpp:264: "Could not find a newline character at the end of the file." [whitespace/ending_newline] [5] diff --git a/samples/silly-sample/simple.def b/samples/silly-sample/simple.def index f0233a3..e9a3fee 100644 --- a/samples/silly-sample/simple.def +++ b/samples/silly-sample/simple.def @@ -1,11 +1,18 @@ -src/*.cpp +src/* 1 -3 +4 Done processing src/sillycode.cpp -Total errors found: 111 +Done processing src/sillycode.w +Total errors found: 126 src/sillycode.cpp:0: No copyright message found. You should have a line: "Copyright [year] " [legal/copyright] [5] -src/sillycode.cpp:3: Found C system header after C++ system header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] +src/sillycode.cpp:1: Include the directory when naming header files [build/include_subdir] [4] +src/sillycode.cpp:2: At least two spaces is best between code and comments [whitespace/comments] [2] +src/sillycode.cpp:2: Should have a space between // and comment [whitespace/comments] [4] +src/sillycode.cpp:2: is an unapproved C++11 header. [build/c++11] [5] +src/sillycode.cpp:3: Found C system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] +src/sillycode.cpp:4: Found C system header after other header. Should be: sillycode.h, c system, c++ system, other. [build/include_order] [4] +src/sillycode.cpp:5: Do not use namespace using-directives. Use using-declarations instead. [build/namespaces] [5] src/sillycode.cpp:8: public: should be indented +1 space inside class Date [whitespace/indent] [3] src/sillycode.cpp:14: Is this a non-const reference? If so, make const or use a pointer: vector& v [runtime/references] [2] src/sillycode.cpp:15: { should almost always be at the end of the previous line [whitespace/braces] [4] @@ -31,7 +38,6 @@ src/sillycode.cpp:80: At least two spaces is best between code and comments [w src/sillycode.cpp:84: public: should be indented +1 space inside class X3 [whitespace/indent] [3] src/sillycode.cpp:85: Constructors callable with one argument should be marked explicit. [runtime/explicit] [4] src/sillycode.cpp:86: Tab found; better to use spaces [whitespace/tab] [1] -src/sillycode.cpp:86: Lines should be <= 80 characters long [whitespace/line_length] [2] src/sillycode.cpp:94: public: should be indented +1 space inside class Foo [whitespace/indent] [3] src/sillycode.cpp:100: { should almost always be at the end of the previous line [whitespace/braces] [4] src/sillycode.cpp:110: Tab found; better to use spaces [whitespace/tab] [1] @@ -99,20 +105,30 @@ src/sillycode.cpp:228: At least two spaces is best between code and comments [ src/sillycode.cpp:228: Using C-style cast. Use reinterpret_cast(...) instead [readability/casting] [4] src/sillycode.cpp:236: public: should be indented +1 space inside class derived2 [whitespace/indent] [3] src/sillycode.cpp:241: At least two spaces is best between code and comments [whitespace/comments] [2] -src/sillycode.cpp:243: Lines should be <= 80 characters long [whitespace/line_length] [2] +src/sillycode.cpp:243: Lines should be <= 84 characters long [whitespace/line_length] [2] src/sillycode.cpp:243: At least two spaces is best between code and comments [whitespace/comments] [2] src/sillycode.cpp:243: Using C-style cast. Use reinterpret_cast(...) instead [readability/casting] [4] -src/sillycode.cpp:244: Lines should be <= 80 characters long [whitespace/line_length] [2] +src/sillycode.cpp:244: Lines should be <= 84 characters long [whitespace/line_length] [2] src/sillycode.cpp:244: At least two spaces is best between code and comments [whitespace/comments] [2] +src/sillycode.cpp:249: Line ends in whitespace. Consider deleting these extra spaces. [whitespace/end_of_line] [4] +src/sillycode.cpp:249: Lines should be <= 84 characters long [whitespace/line_length] [2] +src/sillycode.cpp:249: At least two spaces is best between code and comments [whitespace/comments] [2] +src/sillycode.cpp:249: Missing space before { [whitespace/braces] [5] src/sillycode.cpp:253: At least two spaces is best between code and comments [whitespace/comments] [2] src/sillycode.cpp:254: At least two spaces is best between code and comments [whitespace/comments] [2] src/sillycode.cpp:257: Tab found; better to use spaces [whitespace/tab] [1] src/sillycode.cpp:257: At least two spaces is best between code and comments [whitespace/comments] [2] src/sillycode.cpp:260: Empty loop bodies should use {} or continue [whitespace/empty_loop_body] [5] src/sillycode.cpp:260: At least two spaces is best between code and comments [whitespace/comments] [2] +src/sillycode.cpp:263: Redundant blank line at the end of a code block should be deleted. [whitespace/blank_line] [3] +src/sillycode.cpp:14: Add #include for vector<> [build/include_what_you_use] [4] src/sillycode.cpp:126: Add #include for swap [build/include_what_you_use] [4] src/sillycode.cpp:168: Add #include for unique_ptr<> [build/include_what_you_use] [4] +src/sillycode.cpp:179: Add #include for cin [build/include_what_you_use] [4] src/sillycode.cpp:224: Add #include for numeric_limits<> [build/include_what_you_use] [4] src/sillycode.cpp:237: Add #include for string [build/include_what_you_use] [4] -src/sillycode.cpp:244: Add #include for cout [build/include_what_you_use] [4] +src/sillycode.cpp:264: Could not find a newline character at the end of the file. [whitespace/ending_newline] [5] +src/sillycode.w:0: No copyright message found. You should have a line: "Copyright [year] " [legal/copyright] [5] +src/sillycode.w:0: No #ifndef header guard found, suggested CPP variable is: SAMPLES_SILLY_SAMPLE_SRC_SILLYCODE_W_ [build/header_guard] [5] +src/sillycode.w:3: Should have a space between // and comment [whitespace/comments] [4] diff --git a/samples/silly-sample/src/sillycode.cpp b/samples/silly-sample/src/sillycode.cpp index 45c294d..9303327 100644 --- a/samples/silly-sample/src/sillycode.cpp +++ b/samples/silly-sample/src/sillycode.cpp @@ -1,8 +1,8 @@ -#include - -#include - -#include +#include "stdckdint.omg" +#include "ratio" //kewl headers, living the life! +#include +#include // corresponding header file +using namespace std; class Date { // ... public: @@ -241,13 +241,13 @@ derived1 d1; base* p = &d1; // ok, implicit conversion to pointer to base is fine derived2* p2 = (derived2*)(p); // BAD, tries to treat d1 as a derived2, which it is not -cout << p2.get_s(); // tries to access d1's nonexistent string member, instead sees arbitrary bytes near d1 +println("{}", p2->get_s()); // tries to access d1's nonexistent string member, instead sees arbitrary bytes near d1 void f(const int& i) { (int&)(i) = 42; // BAD } - -static int i = 0; +inline incorrect_FUNCTIONnaMe(){ // This inline function is too long (over 10 lines) + static int i = 0; static const int j = 0; f(i); // silent side effect @@ -260,3 +260,5 @@ int i; for (i = 0; i < max; ++i); // bug waiting to happen if (i == j) return i; + +} \ No newline at end of file diff --git a/samples/silly-sample/src/sillycode.w b/samples/silly-sample/src/sillycode.w new file mode 100644 index 0000000..a6431f6 --- /dev/null +++ b/samples/silly-sample/src/sillycode.w @@ -0,0 +1,6 @@ +// super copy paste go +#include +//forward declarations +class B; +void FuncInB(); +extern int variable_in_b;