diff --git a/scripts/tabs.pl b/scripts/tabs.pl new file mode 100755 index 000000000..bf58359ae --- /dev/null +++ b/scripts/tabs.pl @@ -0,0 +1,35 @@ +#!/usr/bin/perl +# warn if there are tabs in string constants, it can have surprising effects. +# example usage: +# scripts/tabs.pl lib/checkstl.cpp + +sub checkfile +{ + my $filename = $_[0]; + + # parse file + open(FILE, $filename); + my @lines = ; + close(FILE); + + # check comments.. + my $linenr = 0; + foreach $line (@lines) + { + $linenr = $linenr + 1; + + # is there a tab in a string + if ($line =~ /".*\t.*"/) + { + print "[$filename:$linenr] tab inside string constant\n"; + } + } +} + + +foreach $filename (@ARGV) +{ + checkfile($filename) +} + + diff --git a/test/testclass.cpp b/test/testclass.cpp index a8cb213e1..fd284f8fb 100644 --- a/test/testclass.cpp +++ b/test/testclass.cpp @@ -488,11 +488,11 @@ private: " UString& operator=( const UString& s );\n" "};\n" "UString& UString::assign( const char* c_str ) {\n" - " std::string tmp( c_str );\n" - " return assign( tmp );\n" + " std::string tmp( c_str );\n" + " return assign( tmp );\n" "}\n" "UString& UString::operator=( const UString& s ) {\n" - " return assign( s );\n" + " return assign( s );\n" "}\n"); } @@ -2723,7 +2723,7 @@ private: " A()\n" " {\n" " init();\n" - " }\n" + " }\n" "\n" " void init() { init(0); }\n" "\n" @@ -5452,12 +5452,12 @@ private: checkConst("template class E,class D> class C : E\n" "{\n" "public:\n" - " int f();\n" + " int f();\n" "};\n" "class E : C\n" "{\n" "public:\n" - " int f() { return C< ::D,int>::f(); }\n" + " int f() { return C< ::D,int>::f(); }\n" "};\n"); ASSERT_EQUALS("", errout.str()); diff --git a/test/testmathlib.cpp b/test/testmathlib.cpp index f05a029bc..cd3637da3 100644 --- a/test/testmathlib.cpp +++ b/test/testmathlib.cpp @@ -66,20 +66,20 @@ private: ASSERT_EQUALS("3000" , MathLib::multiply("1.0E3", "3")); ASSERT_EQUALS("-3000" , MathLib::multiply("-1.0E3", "3")); ASSERT_EQUALS("-3000" , MathLib::multiply("-1.0E+3", "3")); - ASSERT_EQUALS("0" , MathLib::multiply("-1.0E+3", "0")); - ASSERT_EQUALS("0" , MathLib::multiply("+1.0E+3", "0")); - ASSERT_EQUALS("2147483648" , MathLib::multiply("2","1073741824")); - ASSERT_EQUALS("536870912" , MathLib::multiply("512","1048576")); + ASSERT_EQUALS("0" , MathLib::multiply("-1.0E+3", "0")); + ASSERT_EQUALS("0" , MathLib::multiply("+1.0E+3", "0")); + ASSERT_EQUALS("2147483648" , MathLib::multiply("2","1073741824")); + ASSERT_EQUALS("536870912" , MathLib::multiply("512","1048576")); // divide - ASSERT_EQUALS("1" , MathLib::divide("1", "1")); - ASSERT_EQUALS("0" , MathLib::divide("0", "1")); - ASSERT_EQUALS("5" , MathLib::divide("-10", "-2")); + ASSERT_EQUALS("1" , MathLib::divide("1", "1")); + ASSERT_EQUALS("0" , MathLib::divide("0", "1")); + ASSERT_EQUALS("5" , MathLib::divide("-10", "-2")); ASSERT_EQUALS("-2.5", MathLib::divide("-10.", "4")); ASSERT_EQUALS("2.5" , MathLib::divide("-10.", "-4")); - ASSERT_EQUALS("5" , MathLib::divide("25.5", "5.1")); - ASSERT_EQUALS("7" , MathLib::divide("21.", "3")); - ASSERT_EQUALS("1" , MathLib::divide("3", "2")); + ASSERT_EQUALS("5" , MathLib::divide("25.5", "5.1")); + ASSERT_EQUALS("7" , MathLib::divide("21.", "3")); + ASSERT_EQUALS("1" , MathLib::divide("3", "2")); } diff --git a/test/testnullpointer.cpp b/test/testnullpointer.cpp index 0c9e09a1f..35b239974 100644 --- a/test/testnullpointer.cpp +++ b/test/testnullpointer.cpp @@ -668,7 +668,7 @@ private: check("void f(int a) {\n" " const char *p = 0;\n" " if (a) {\n" - " p = \"abcd\";\n" + " p = \"abcd\";\n" " }\n" " for (int i = 0; i < 3; i++) {\n" " if (a && (p[i] == '1'));\n" diff --git a/test/testuninitvar.cpp b/test/testuninitvar.cpp index 9c24fe6a5..3dc598f83 100644 --- a/test/testuninitvar.cpp +++ b/test/testuninitvar.cpp @@ -736,9 +736,9 @@ private: checkUninitVar("enum ABCD { A, B, C, D };\n" "\n" "static void f(char *str ) {\n" - " enum ABCD i;\n" - " for (i = 0; i < D; i++) {\n" - " str[i] = 0;\n" + " enum ABCD i;\n" + " for (i = 0; i < D; i++) {\n" + " str[i] = 0;\n" " }\n" "}\n"); ASSERT_EQUALS("", errout.str());