Skip to content

Commit 43419fe

Browse files
authored
made CppCheck::getClangFlags() an internal function (danmar#7412)
1 parent 07eb1f0 commit 43419fe

File tree

4 files changed

+21
-28
lines changed

4 files changed

+21
-28
lines changed

lib/cppcheck.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -612,32 +612,37 @@ std::string CppCheck::getLibraryDumpData() const {
612612
return out;
613613
}
614614

615-
std::string CppCheck::getClangFlags(Standards::Language lang) const {
615+
/**
616+
* @brief Get the clang command line flags using the Settings
617+
* @param lang language guessed from filename
618+
* @return Clang command line flags
619+
*/
620+
static std::string getClangFlags(const Settings& setting, Standards::Language lang) {
616621
std::string flags;
617622

618623
assert(lang != Standards::Language::None);
619624

620625
switch (lang) {
621626
case Standards::Language::C:
622627
flags = "-x c ";
623-
if (!mSettings.standards.stdValueC.empty())
624-
flags += "-std=" + mSettings.standards.stdValueC + " ";
628+
if (!setting.standards.stdValueC.empty())
629+
flags += "-std=" + setting.standards.stdValueC + " ";
625630
break;
626631
case Standards::Language::CPP:
627632
flags += "-x c++ ";
628-
if (!mSettings.standards.stdValueCPP.empty())
629-
flags += "-std=" + mSettings.standards.stdValueCPP + " ";
633+
if (!setting.standards.stdValueCPP.empty())
634+
flags += "-std=" + setting.standards.stdValueCPP + " ";
630635
break;
631636
case Standards::Language::None:
632637
break;
633638
}
634639

635-
for (const std::string &i: mSettings.includePaths)
640+
for (const std::string &i: setting.includePaths)
636641
flags += "-I" + i + " ";
637642

638-
flags += getDefinesFlags(mSettings.userDefines);
643+
flags += getDefinesFlags(setting.userDefines);
639644

640-
for (const std::string &i: mSettings.userIncludes)
645+
for (const std::string &i: setting.userIncludes)
641646
flags += "--include " + cmdFileName(i) + " ";
642647

643648
return flags;
@@ -668,7 +673,7 @@ unsigned int CppCheck::checkClang(const FileWithDetails &file)
668673
#endif
669674

670675
const std::string args2 = "-fsyntax-only -Xclang -ast-dump -fno-color-diagnostics " +
671-
getClangFlags(file.lang()) +
676+
getClangFlags(mSettings, file.lang()) +
672677
file.spath();
673678
const std::string redirect2 = clangStderr.empty() ? "2>&1" : ("2> " + clangStderr);
674679
if (mSettings.verbose && !mSettings.quiet) {

lib/cppcheck.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include "check.h"
2525
#include "config.h"
26-
#include "standards.h"
2726

2827
#include <cstdint>
2928
#include <fstream>
@@ -151,13 +150,6 @@ class CPPCHECKLIB CppCheck {
151150

152151
std::string getLibraryDumpData() const;
153152

154-
/**
155-
* @brief Get the clang command line flags using the Settings
156-
* @param lang language guessed from filename
157-
* @return Clang command line flags
158-
*/
159-
std::string getClangFlags(Standards::Language lang) const;
160-
161153
private:
162154
#ifdef HAVE_RULES
163155
/** Are there "simple" rules */

test/cli/clang-import_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ def test_cmd_def(tmp_path):
197197
__test_cmd(tmp_path, 'test.cpp',['-DDEF'], '-x c++ -DDEF=1')
198198

199199

200+
def test_cmd_include(tmp_path):
201+
inc_file = tmp_path / 'inc.h'
202+
with open(inc_file, 'wt'):
203+
pass
204+
__test_cmd(tmp_path, 'test.cpp',['--include=inc.h'], '-x c++ --include inc.h')
205+
206+
200207
def test_cmd_enforce_c(tmp_path): # #13128
201208
__test_cmd(tmp_path, 'test.cpp',['-x', 'c'], '-x c')
202209

test/testcppcheck.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
#include "fixture.h"
2424
#include "helpers.h"
2525
#include "settings.h"
26-
#include "standards.h"
2726
#include "suppressions.h"
2827

2928
#include "simplecpp.h"
@@ -64,7 +63,6 @@ class TestCppcheck : public TestFixture {
6463
TEST_CASE(isPremiumCodingStandardId);
6564
TEST_CASE(getDumpFileContentsRawTokens);
6665
TEST_CASE(getDumpFileContentsLibrary);
67-
TEST_CASE(getClangFlagsIncludeFile);
6866
}
6967

7068
void getErrorMessages() const {
@@ -327,15 +325,6 @@ class TestCppcheck : public TestFixture {
327325
}
328326
}
329327

330-
void getClangFlagsIncludeFile() const {
331-
Settings s;
332-
s.userIncludes.emplace_back("1.h");
333-
Suppressions supprs;
334-
ErrorLogger2 errorLogger;
335-
CppCheck cppcheck(s, supprs, errorLogger, false, {});
336-
ASSERT_EQUALS("-x c --include 1.h ", cppcheck.getClangFlags(Standards::Language::C));
337-
}
338-
339328
// TODO: test suppressions
340329
// TODO: test all with FS
341330
};

0 commit comments

Comments
 (0)