Skip to content

Commit 442b5cd

Browse files
committed
s [skip ci]
1 parent 688e140 commit 442b5cd

File tree

10 files changed

+32
-32
lines changed

10 files changed

+32
-32
lines changed

cli/cmdlineparser.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
547547
}
548548
}
549549

550-
else if (std::strcmp(argv[i], "--cpp-probe") == 0) {
551-
mSettings.cppProbe = true;
550+
else if (std::strcmp(argv[i], "--cpp-header-probe") == 0) {
551+
mSettings.cppHeaderProbe = true;
552552
}
553553

554554
// Show --debug output after the first simplifications
@@ -895,7 +895,7 @@ CmdLineParser::Result CmdLineParser::parseFromArgs(int argc, const char* const a
895895
}
896896

897897
else if (std::strcmp(argv[i], "--no-cpp-probe") == 0) {
898-
mSettings.cppProbe = false;
898+
mSettings.cppHeaderProbe = false;
899899
}
900900

901901
// Write results in file

lib/cppcheck.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ static void createDumpFile(const Settings& settings,
182182
case Standards::Language::None:
183183
{
184184
// TODO: error out on unknown language?
185-
const Standards::Language lang = Path::identify(filename, settings.cppProbe);
185+
const Standards::Language lang = Path::identify(filename, settings.cppHeaderProbe);
186186
if (lang == Standards::Language::CPP)
187187
language = " language=\"cpp\"";
188188
else if (lang == Standards::Language::C)
@@ -420,7 +420,7 @@ unsigned int CppCheck::checkClang(const std::string &path)
420420
mErrorLogger.reportOut(std::string("Checking ") + path + " ...", Color::FgGreen);
421421

422422
// TODO: this ignores the configured language
423-
const bool isCpp = Path::identify(path, mSettings.cppProbe) == Standards::Language::CPP;
423+
const bool isCpp = Path::identify(path, mSettings.cppHeaderProbe) == Standards::Language::CPP;
424424
const std::string langOpt = isCpp ? "-x c++" : "-x c";
425425
const std::string analyzerInfo = mSettings.buildDir.empty() ? std::string() : AnalyzerInformation::getAnalyzerInfoFile(mSettings.buildDir, path, emptyString);
426426
const std::string clangcmd = analyzerInfo + ".clang-cmd";

lib/path.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,15 +301,15 @@ static bool hasEmacsCppMarker(const char* path)
301301
return false; // marker is not a C++ one
302302
}
303303

304-
Standards::Language Path::identify(const std::string &path, bool cppProbe, bool *header)
304+
Standards::Language Path::identify(const std::string &path, bool cppHeaderProbe, bool *header)
305305
{
306306
// cppcheck-suppress uninitvar - TODO: FP
307307
if (header)
308308
*header = false;
309309

310310
std::string ext = getFilenameExtension(path);
311311
// standard library headers have no extension
312-
if (cppProbe && ext.empty()) {
312+
if (cppHeaderProbe && ext.empty()) {
313313
if (hasEmacsCppMarker(path.c_str())) {
314314
if (header)
315315
*header = true;
@@ -326,7 +326,7 @@ Standards::Language Path::identify(const std::string &path, bool cppProbe, bool
326326
if (ext == ".h") {
327327
if (header)
328328
*header = true;
329-
if (cppProbe && hasEmacsCppMarker(path.c_str()))
329+
if (cppHeaderProbe && hasEmacsCppMarker(path.c_str()))
330330
return Standards::Language::CPP;
331331
return Standards::Language::C;
332332
}

lib/path.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ class CPPCHECKLIB Path {
187187
/**
188188
* @brief Identify the language based on the file extension
189189
* @param path filename to check. path info is optional
190-
* @param cppProbe check optional Emacs marker to idengtify headers as C++
190+
* @param cppHeaderProbe check optional Emacs marker to identify extension-less and *.h files as C++
191191
* @param header if provided indicates if the file is a header
192192
* @return the language type
193193
*/
194-
static Standards::Language identify(const std::string &path, bool cppProbe, bool *header = nullptr);
194+
static Standards::Language identify(const std::string &path, bool cppHeaderProbe, bool *header = nullptr);
195195

196196
/**
197197
* @brief Get filename without a directory path part.

lib/preprocessor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ static simplecpp::DUI createDUI(const Settings &mSettings, const std::string &cf
684684
dui.includes = mSettings.userIncludes; // --include
685685
// TODO: use mSettings.standards.stdValue instead
686686
// TODO: error out on unknown language?
687-
const Standards::Language lang = Path::identify(filename, mSettings.cppProbe);
687+
const Standards::Language lang = Path::identify(filename, mSettings.cppHeaderProbe);
688688
if (lang == Standards::Language::CPP) {
689689
dui.std = mSettings.standards.getCPP();
690690
splitcfg(mSettings.platform.getLimitsDefines(Standards::getCPP(dui.std)), dui.defines, "");

lib/settings.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ class CPPCHECKLIB WARN_UNUSED Settings {
167167
/** cppcheck.cfg: About text */
168168
std::string cppcheckCfgAbout;
169169

170-
/** @brief check Emacs marker to detect header files as C++ */
171-
bool cppProbe{};
170+
/** @brief check Emacs marker to detect extension-less and *.h files as C++ */
171+
bool cppHeaderProbe{};
172172

173173
/** @brief Are we running from DACA script? */
174174
bool daca{};

lib/tokenlist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void TokenList::determineCppC()
9696
// only try to determine if it wasn't enforced
9797
if (mLang == Standards::Language::None) {
9898
ASSERT_LANG(!getSourceFilePath().empty());
99-
mLang = Path::identify(getSourceFilePath(), mSettings ? mSettings->cppProbe : false);
99+
mLang = Path::identify(getSourceFilePath(), mSettings ? mSettings->cppHeaderProbe : false);
100100
// TODO: cannot enable assert as this might occur for unknown extensions
101101
//ASSERT_LANG(mLang != Standards::Language::None);
102102
if (mLang == Standards::Language::None) {

releasenotes.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ Deprecations:
1616
-
1717

1818
Other:
19+
- added command-line option `--cpp-header-probe` (and `--no-cpp-header-probe`) to probe headers and extension-less files for Emacs marker (see https://trac.cppcheck.net/ticket/10692 for more details)
1920
-

test/cli/other_test.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,7 @@ def test_cpp_probe(tmpdir):
14371437
'class A {};'
14381438
])
14391439

1440-
args = ['-q', '--template=simple', '--cpp-probe', test_file]
1440+
args = ['-q', '--template=simple', '--cpp-header-probe', test_file]
14411441
err_lines = [
14421442
"{}:1:1: error: Code 'classA{{' is invalid C code. Use --std or --language to configure the language. [syntaxError]".format(test_file)
14431443
]
@@ -1453,7 +1453,6 @@ def test_cpp_probe_2(tmpdir):
14531453
'class A {};'
14541454
])
14551455

1456-
# TODO: the probing is performed twice
1457-
args = ['-q', '--template=simple', '--cpp-probe', test_file]
1456+
args = ['-q', '--template=simple', '--cpp-header-probe', test_file]
14581457

14591458
assert_cppcheck(args, ec_exp=0, err_exp=[], out_exp=[])

test/testcmdlineparser.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,10 @@ class TestCmdlineParser : public TestFixture {
387387
TEST_CASE(checkLevelNormal);
388388
TEST_CASE(checkLevelExhaustive);
389389
TEST_CASE(checkLevelUnknown);
390-
TEST_CASE(cppProbe);
391-
TEST_CASE(cppProbe2);
392-
TEST_CASE(noCppProbe);
393-
TEST_CASE(noCppProbe2);
390+
TEST_CASE(cppHeaderProbe);
391+
TEST_CASE(cppHeaderProbe2);
392+
TEST_CASE(noCppHeaderProbe);
393+
TEST_CASE(noCppHeaderProbe2);
394394

395395
TEST_CASE(ignorepaths1);
396396
TEST_CASE(ignorepaths2);
@@ -2607,32 +2607,32 @@ class TestCmdlineParser : public TestFixture {
26072607
ASSERT_EQUALS("cppcheck: error: unknown '--check-level' value 'default'.\n", logger->str());
26082608
}
26092609

2610-
void cppProbe() {
2610+
void cppHeaderProbe() {
26112611
REDIRECT;
2612-
const char * const argv[] = {"cppcheck", "--cpp-probe", "file.cpp"};
2612+
const char * const argv[] = {"cppcheck", "--cpp-header-probe", "file.cpp"};
26132613
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
2614-
ASSERT_EQUALS(true, settings->cppProbe);
2614+
ASSERT_EQUALS(true, settings->cppHeaderProbe);
26152615
}
26162616

2617-
void cppProbe2() {
2617+
void cppHeaderProbe2() {
26182618
REDIRECT;
2619-
const char * const argv[] = {"cppcheck", "--no-cpp-probe", "--cpp-probe", "file.cpp"};
2619+
const char * const argv[] = {"cppcheck", "--no-cpp-header-probe", "--cpp-header-probe", "file.cpp"};
26202620
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv));
2621-
ASSERT_EQUALS(true, settings->cppProbe);
2621+
ASSERT_EQUALS(true, settings->cppHeaderProbe);
26222622
}
26232623

2624-
void noCppProbe() {
2624+
void noCppHeaderProbe() {
26252625
REDIRECT;
26262626
const char * const argv[] = {"cppcheck", "--no-cpp-probe", "file.cpp"};
26272627
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(3, argv));
2628-
ASSERT_EQUALS(false, settings->cppProbe);
2628+
ASSERT_EQUALS(false, settings->cppHeaderProbe);
26292629
}
26302630

2631-
void noCppProbe2() {
2631+
void noCppHeaderProbe2() {
26322632
REDIRECT;
2633-
const char * const argv[] = {"cppcheck", "--cpp-probe", "--no-cpp-probe", "file.cpp"};
2633+
const char * const argv[] = {"cppcheck", "--cpp-header-probe", "--no-cpp-probe", "file.cpp"};
26342634
ASSERT_EQUALS_ENUM(CmdLineParser::Result::Success, parser->parseFromArgs(4, argv));
2635-
ASSERT_EQUALS(false, settings->cppProbe);
2635+
ASSERT_EQUALS(false, settings->cppHeaderProbe);
26362636
}
26372637

26382638
void ignorepaths1() {

0 commit comments

Comments
 (0)