Skip to content
Draft
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
4 changes: 3 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Checks: >
-cppcoreguidelines-*,
-fuchsia-*,
-google-*,
-hicpp-*,
-linuxkernel-*,
-llvm-*,
-llvmlibc-*,
Expand All @@ -21,6 +20,8 @@ Checks: >
-bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
-bugprone-narrowing-conversions,
-bugprone-signed-bitwise,
-bugprone-std-exception-baseclass,
-bugprone-switch-missing-default-case,
-bugprone-throwing-static-initialization,
-bugprone-unchecked-string-to-number-conversion,
Expand All @@ -42,6 +43,7 @@ Checks: >
-readability-isolate-declaration,
-readability-magic-numbers,
-readability-redundant-inline-specifier,
-readability-trailing-comma,
-readability-use-concise-preprocessor-directives,
-readability-uppercase-literal-suffix,
-performance-avoid-endl,
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/clang-tidy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ jobs:
run: |
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 22
sudo apt-get install clang-tidy-22
sudo ./llvm.sh 23
sudo apt-get install clang-tidy-23

- name: Verify clang-tidy configuration
run: |
clang-tidy-22 --verify-config
clang-tidy-23 --verify-config

- name: Prepare CMake
run: |
cmake -S . -B cmake.output -Werror=dev --warn-uninitialized -DCMAKE_CXX_STANDARD=23 -DCMAKE_COMPILE_WARNING_AS_ERROR=On -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
env:
CXX: clang-22
CXX: clang-23

- name: Clang-Tidy
run: |
run-clang-tidy-22 -q -j $(nproc) -enable-check-profile -p=cmake.output
run-clang-tidy-23 -q -j $(nproc) -enable-check-profile -p=cmake.output
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options_safe(-Wno-thread-safety-negative)
add_compile_options_safe(-Wno-thread-safety-beta)

# TODO: enable
add_compile_options_safe(-Wno-lifetime-safety-intra-tu-suggestions)
add_compile_options_safe(-Wno-lifetime-safety-intra-tu-constructor-suggestions)
add_compile_options_safe(-Wno-lifetime-safety-cross-tu-constructor-suggestions)

# TODO: fix these?
add_compile_options(-Wno-padded)
add_compile_options(-Wno-sign-conversion)
Expand Down
3 changes: 2 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ static bool isDir(const std::string& path)
return (file_stat.st_mode & S_IFMT) == S_IFDIR;
}

int main(int argc, char **argv)
int main(int argc, char *argv[])
{
bool error = false;
const char *filename = nullptr;
Expand All @@ -49,6 +49,7 @@ int main(int argc, char **argv)
if (*arg == '-') {
bool found = false;
const char c = arg[1];
// NOLINTNEXTLINE(bugprone-unhandled-code-paths)
switch (c) {
case 'D': { // define symbol
found = true;
Expand Down
29 changes: 15 additions & 14 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ static bool endsWith(const std::string &s, const std::string &e)
return (s.size() >= e.size()) && std::equal(e.rbegin(), e.rend(), s.rbegin());
}

static bool sameline(const simplecpp::Token *tok1, const simplecpp::Token *tok2)
static bool sameline(const simplecpp::Token * const tok1, const simplecpp::Token * const tok2)
{
return tok1 && tok2 && tok1->location.sameline(tok2->location);
}

static bool isAlternativeBinaryOp(const simplecpp::Token *tok, const std::string &alt)
static bool isAlternativeBinaryOp(const simplecpp::Token * const tok, const std::string &alt)
{
return (tok->name &&
tok->str() == alt &&
Expand All @@ -168,7 +168,7 @@ static bool isAlternativeBinaryOp(const simplecpp::Token *tok, const std::string
(tok->next->number || tok->next->name || tok->next->op == '('));
}

static bool isAlternativeUnaryOp(const simplecpp::Token *tok, const std::string &alt)
static bool isAlternativeUnaryOp(const simplecpp::Token * const tok, const std::string &alt)
{
return ((tok->name && tok->str() == alt) &&
(!tok->previous || tok->previous->op == '(') &&
Expand Down Expand Up @@ -622,7 +622,7 @@ static std::string escapeString(const std::string &str)
return ostr.str();
}

static void portabilityBackslash(simplecpp::OutputList *outputList, const simplecpp::Location &location)
static void portabilityBackslash(simplecpp::OutputList * const outputList, const simplecpp::Location &location)
{
if (!outputList)
return;
Expand Down Expand Up @@ -799,7 +799,7 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
if (ch == '\\') {
TokenString tmp;
char tmp_ch = ch;
while ((stream.good()) && (tmp_ch == '\\' || tmp_ch == ' ' || tmp_ch == '\t')) {
while (stream.good() && (tmp_ch == '\\' || tmp_ch == ' ' || tmp_ch == '\t')) {
tmp += tmp_ch;
tmp_ch = stream.readChar();
}
Expand Down Expand Up @@ -999,7 +999,7 @@ void simplecpp::TokenList::constFold()
}
}

static bool isFloatSuffix(const simplecpp::Token *tok)
static bool isFloatSuffix(const simplecpp::Token * const tok)
{
if (!tok || tok->str().size() != 1U)
return false;
Expand All @@ -1010,7 +1010,7 @@ static bool isFloatSuffix(const simplecpp::Token *tok)
static const std::string AND("and");
static const std::string BITAND("bitand");
static const std::string BITOR("bitor");
static bool isAlternativeAndBitandBitor(const simplecpp::Token* tok)
static bool isAlternativeAndBitandBitor(const simplecpp::Token * const tok)
{
return isAlternativeBinaryOp(tok, AND) || isAlternativeBinaryOp(tok, BITAND) || isAlternativeBinaryOp(tok, BITOR);
}
Expand Down Expand Up @@ -1699,7 +1699,7 @@ namespace simplecpp {
};

struct invalidDirectiveAsMacroParameter : public Error {
invalidDirectiveAsMacroParameter(const Location &loc)
explicit invalidDirectiveAsMacroParameter(const Location &loc)
: Error(loc, "it is invalid to use a preprocessor directive as macro parameter") {}
};

Expand Down Expand Up @@ -2296,7 +2296,7 @@ namespace simplecpp {
* @return token after B
*/
const Token *expandHashHash(TokenList &output, const Location &loc, const Token *tok, const MacroMap &macros, const std::set<TokenString> &expandedmacros, const std::vector<const Token*> &parametertokens, bool expandResult=true) const {
Token *A = output.back();
Token * const A = output.back();
if (!A)
throw invalidHashHash(tok->location, name(), "Missing first argument");
if (!sameline(tok, tok->next) || !sameline(tok, tok->next->next))
Expand Down Expand Up @@ -3258,7 +3258,7 @@ static bool getFileId(const std::string &path, FileID &id)
#endif
}

simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens, std::vector<std::string> &filenames, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, FileDataCache cache)
simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens, std::vector<std::string> &filenames, const simplecpp::DUI &dui, simplecpp::OutputList * const outputList, FileDataCache cache)
{
#ifdef SIMPLECPP_WINDOWS
if (dui.clearIncludeCache)
Expand Down Expand Up @@ -3341,7 +3341,7 @@ simplecpp::FileDataCache simplecpp::load(const simplecpp::TokenList &rawtokens,
return cache;
}

static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token *&tok1, simplecpp::MacroMap &macros, std::vector<std::string> &files, simplecpp::OutputList *outputList)
static bool preprocessToken(simplecpp::TokenList &output, const simplecpp::Token *&tok1, simplecpp::MacroMap &macros, std::vector<std::string> &files, simplecpp::OutputList * const outputList)
{
const simplecpp::Token * const tok = tok1;
const simplecpp::MacroMap::const_iterator it = tok->name ? macros.find(tok->str()) : macros.end();
Expand Down Expand Up @@ -3391,21 +3391,21 @@ static void getLocaltime(struct tm &ltime)
#endif
}

static std::string getDateDefine(const struct tm *timep)
static std::string getDateDefine(const struct tm * const timep)
{
char buf[] = "??? ?? ????";
strftime(buf, sizeof(buf), "%b %d %Y", timep);
return std::string("\"").append(buf).append("\"");
}

static std::string getTimeDefine(const struct tm *timep)
static std::string getTimeDefine(const struct tm * const timep)
{
char buf[] = "??:??:??";
strftime(buf, sizeof(buf), "%H:%M:%S", timep);
return std::string("\"").append(buf).append("\"");
}

void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, simplecpp::FileDataCache &cache, const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage, std::list<simplecpp::IfCond> *ifCond)
void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenList &rawtokens, std::vector<std::string> &files, simplecpp::FileDataCache &cache, const simplecpp::DUI &dui, simplecpp::OutputList * const outputList, std::list<simplecpp::MacroUsage> * const macroUsage, std::list<simplecpp::IfCond> * const ifCond)
{
#ifdef SIMPLECPP_WINDOWS
if (dui.clearIncludeCache)
Expand Down Expand Up @@ -3783,6 +3783,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
std::string header;

if (systemheader) {
// NOLINTNEXTLINE(bugprone-assignment-in-selection-statement)
while ((tok = tok->next) && tok->op != '>')
header += tok->str();
if (tok && tok->op == '>')
Expand Down
2 changes: 2 additions & 0 deletions simplecpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace simplecpp {
struct View
{
// cppcheck-suppress noExplicitConstructor
// NOLINTNEXTLINE(misc-explicit-constructor)
View(const char* data)
: mData(data)
, mSize(strlen(data))
Expand All @@ -88,6 +89,7 @@ namespace simplecpp {
{}

// cppcheck-suppress noExplicitConstructor
// NOLINTNEXTLINE(misc-explicit-constructor)
View(const std::string& str)
: mData(str.data())
, mSize(str.size())
Expand Down
22 changes: 11 additions & 11 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ static void assertThrowFailed(int line)
std::cerr << "exception not thrown" << std::endl;
}

static void testcase(const std::string &name, void (*f)(), int argc, char * const *argv)
static void testcase(const std::string &name, void (*const f)(), int argc, char *argv[])
{
if (argc == 1) {
f();
Expand All @@ -101,7 +101,7 @@ static void testcase(const std::string &name, void (*f)(), int argc, char * cons

#define TEST_CASE(F) (testcase(#F, F, argc, argv))

static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList * const outputList=nullptr)
{
switch (USE_INPUT) {
case Input::Stringstream: {
Expand All @@ -115,24 +115,24 @@ static simplecpp::TokenList makeTokenList(const char code[], std::size_t size, s
return simplecpp::TokenList{filenames}; // unreachable - needed for GCC and Visual Studio
}

static simplecpp::TokenList makeTokenList(const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList *outputList=nullptr)
static simplecpp::TokenList makeTokenList(const char code[], std::vector<std::string> &filenames, const std::string &filename=std::string(), simplecpp::OutputList * const outputList=nullptr)
{
return makeTokenList(code, strlen(code), filenames, filename, outputList);
}

static std::string readfile(const char code[], simplecpp::OutputList *outputList=nullptr)
static std::string readfile(const char code[], simplecpp::OutputList * const outputList=nullptr)
{
std::vector<std::string> files;
return makeTokenList(code,files,std::string(),outputList).stringify();
}

static std::string readfile(const char code[], std::size_t size, simplecpp::OutputList *outputList=nullptr)
static std::string readfile(const char code[], std::size_t size, simplecpp::OutputList * const outputList=nullptr)
{
std::vector<std::string> files;
return makeTokenList(code,size,files,std::string(),outputList).stringify();
}

static std::string preprocess(const char code[], const simplecpp::DUI &dui, simplecpp::OutputList *outputList, std::list<simplecpp::MacroUsage> *macroUsage = nullptr, std::list<simplecpp::IfCond> *ifCond = nullptr, const std::string &file = std::string())
static std::string preprocess(const char code[], const simplecpp::DUI &dui, simplecpp::OutputList * const outputList, std::list<simplecpp::MacroUsage> * const macroUsage = nullptr, std::list<simplecpp::IfCond> * const ifCond = nullptr, const std::string &file = std::string())
{
std::vector<std::string> files;
simplecpp::FileDataCache cache;
Expand Down Expand Up @@ -160,17 +160,17 @@ static std::string preprocess(const char code[], const simplecpp::DUI &dui)
return preprocess(code, dui, nullptr);
}

static std::string preprocess(const char code[], simplecpp::OutputList *outputList)
static std::string preprocess(const char code[], simplecpp::OutputList * const outputList)
{
return preprocess(code, simplecpp::DUI(), outputList);
}

static std::string preprocess(const char code[], std::list<simplecpp::IfCond> *ifCond)
static std::string preprocess(const char code[], std::list<simplecpp::IfCond> * const ifCond)
{
return preprocess(code, simplecpp::DUI(), nullptr, nullptr, ifCond);
}

static std::string preprocess(const char code[], std::list<simplecpp::MacroUsage> *macroUsage)
static std::string preprocess(const char code[], std::list<simplecpp::MacroUsage> * const macroUsage)
{
return preprocess(code, simplecpp::DUI(), nullptr, macroUsage);
}
Expand Down Expand Up @@ -3960,7 +3960,7 @@ static void leak()
}
}

static void runTests(int argc, char **argv, Input input)
static void runTests(int argc, char *argv[], Input input)
{
USE_INPUT = input;

Expand Down Expand Up @@ -4257,7 +4257,7 @@ static void runTests(int argc, char **argv, Input input)
TEST_CASE(leak);
}

int main(int argc, char **argv)
int main(int argc, char *argv[])
{
runTests(argc, argv, Input::Stringstream);
runTests(argc, argv, Input::CharBuffer);
Expand Down
Loading