Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cli/cmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,12 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
else if (std::strcmp(argv[i], "-f") == 0 || std::strcmp(argv[i], "--force") == 0)
mSettings.force = true;

else if (std::strcmp(argv[i], "--fsigned-char") == 0)
mSettings.platform.defaultSign = 's';

else if (std::strcmp(argv[i], "--funsigned-char") == 0)
mSettings.platform.defaultSign = 'u';

// Print help
else if (std::strcmp(argv[i], "-h") == 0 || std::strcmp(argv[i], "--help") == 0) {
mPathNames.clear();
Expand Down Expand Up @@ -1191,6 +1197,8 @@ void CmdLineParser::printHelp() const
" -f, --force Force checking of all configurations in files. If used\n"
" together with '--max-configs=', the last option is the\n"
" one that is effective.\n"
" --fsigned-char Treat char type as signed.\n"
" --funsigned-char Treat char type as unsigned.\n"
" -h, --help Print this help.\n"
" -I <dir> Give path to search for include files. Give several -I\n"
" parameters to give several paths. First given path is\n"
Expand Down
4 changes: 4 additions & 0 deletions lib/importproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,8 @@ void ImportProject::fsParseCommand(FileSettings& fs, const std::string& command)
defs += "__PIE__";
defs += ";";
}
// TODO: support -fsigned-char and -funsigned-char?
// we can only set it globally but in this context it needs to be treated per file
}
}
fsSetDefines(fs, defs);
Expand Down Expand Up @@ -733,6 +735,8 @@ bool ImportProject::importVcxproj(const std::string &filename, std::map<std::str
}
}
}
// # TODO: support signedness of char via /J (and potential XML option for it)?
// we can only set it globally but in this context it needs to be treated per file

for (const std::string &c : compileList) {
const std::string cfilename = Path::simplifyPath(Path::isAbsolute(c) ? c : Path::getPathFromFilename(filename) + c);
Expand Down
22 changes: 22 additions & 0 deletions man/cppcheck.1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ man(1), man(7), http://www.tldp.org/HOWTO/Man-Page/
<arg choice="opt">
<option>--force</option>
</arg>
<arg choice="opt">
<option>--fsigned-char</option>
</arg>
<arg choice="opt">
<option>--funsigned-char</option>
</arg>
<arg choice="opt">
<option>--help</option>
</arg>
Expand Down Expand Up @@ -350,6 +356,22 @@ Example: '-UDEBUG'</para>
default. If used together with --max-configs=, the last option is the one that is effective.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--fsigned-char</option>
</term>
<listitem>
<para>Treat char type as signed. This overrides previous --platform options and is overridden by following ones.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>--funsigned-char</option>
</term>
<listitem>
<para>Treat char type as unsigned. This overrides previous --platform options and is overridden by following ones.</para>
</listitem>
</varlistentry>
<varlistentry>
<term>
<option>-h</option>
Expand Down
1 change: 1 addition & 0 deletions releasenotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ Other:
- You can suppress warnings in current file using "-file".
- You can suppress all warnings where macro is used using "-macro"
- fixed CMake build with UBSAN and GCC
- Added command-line options "--fsigned-char" and "--funsigned-char" to control the signess of the "char" type. This overrides previously specified "--platform" options and is overrides by following ones.
50 changes: 50 additions & 0 deletions test/testcmdlineparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ class TestCmdlineParser : public TestFixture {
#else
TEST_CASE(ruleFileNotSupported);
#endif
TEST_CASE(signedChar);
TEST_CASE(signedChar2);
TEST_CASE(unsignedChar);
TEST_CASE(unsignedChar2);
TEST_CASE(signedCharUnsignedChar);

TEST_CASE(ignorepaths1);
TEST_CASE(ignorepaths2);
Expand Down Expand Up @@ -2067,6 +2072,51 @@ class TestCmdlineParser : public TestFixture {
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}

void signedChar() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--fsigned-char", "file.cpp"};
settings->platform.defaultSign = '\0';
ASSERT(parser->parseFromArgs(3, argv));
ASSERT_EQUALS('s', settings->platform.defaultSign);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}

void signedChar2() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--platform=avr8", "--fsigned-char", "file.cpp"};
settings->platform.defaultSign = '\0';
ASSERT(parser->parseFromArgs(4, argv));
ASSERT_EQUALS('s', settings->platform.defaultSign);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}

void unsignedChar() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--funsigned-char", "file.cpp"};
settings->platform.defaultSign = '\0';
ASSERT(parser->parseFromArgs(3, argv));
ASSERT_EQUALS('u', settings->platform.defaultSign);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}

void unsignedChar2() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--platform=mips32", "--funsigned-char", "file.cpp"};
settings->platform.defaultSign = '\0';
ASSERT(parser->parseFromArgs(4, argv));
ASSERT_EQUALS('u', settings->platform.defaultSign);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}

void signedCharUnsignedChar() {
REDIRECT;
const char * const argv[] = {"cppcheck", "--fsigned-char", "--funsigned-char", "file.cpp"};
settings->platform.defaultSign = '\0';
ASSERT(parser->parseFromArgs(4, argv));
ASSERT_EQUALS('u', settings->platform.defaultSign);
ASSERT_EQUALS("", GET_REDIRECT_OUTPUT);
}

#ifdef HAVE_RULES
void rule() {
REDIRECT;
Expand Down