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
2 changes: 1 addition & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ jobs:

- name: Uncrustify check
run: |
~/uncrustify/uncrustify -c .uncrustify.cfg -l CPP --no-backup --replace */*.cpp */*.h
UNCRUSTIFY=~/uncrustify/uncrustify ./runformat
git diff
git diff | diff - /dev/null &> /dev/null
9 changes: 4 additions & 5 deletions runformat
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash
#
# uncrustify-0.72 is used to format cppcheck source code.
# uncrustify-0.80.1 is used to format cppcheck source code.
#
# 1. Download source code: https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-0.72.0.zip
# 1. Download source code: https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-0.80.1.zip
# It's important that all Cppcheck developers use the exact same version so we don't get a "format battle".
# 2. Building:
# - Linux: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make
Expand All @@ -11,7 +11,7 @@
# - you can put uncrustify in your PATH
# - you can create an environment variable UNCRUSTIFY that has the full path of the binary

UNCRUSTIFY_VERSION="0.72.0"
UNCRUSTIFY_VERSION="0.80.1"
UNCRUSTIFY="${UNCRUSTIFY-uncrustify}"

DETECTED_VERSION=$("$UNCRUSTIFY" --version 2>&1 | grep -o -E '[0-9.]+')
Expand Down Expand Up @@ -40,7 +40,7 @@ function formatCplusplus {
find $1 -iname '*.h' \
-o -iname '*.c' \
-o -iname '*.cpp' \
| xargs -n 1 -P $CPUCOUNT -I{} -t $UNCRUSTIFY -c .uncrustify.cfg --no-backup {}
| xargs -n 1 -P $CPUCOUNT $UNCRUSTIFY -c .uncrustify.cfg -l CPP --no-backup --replace

}

Expand All @@ -51,4 +51,3 @@ formatCplusplus lib/
formatCplusplus oss-fuzz/
formatCplusplus test/
formatCplusplus tools/
formatCplusplus samples/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you remove it here then you also do not need to apply any of the changes.

Also we lack frontend here...

5 changes: 2 additions & 3 deletions samples/passedByValue_1/bad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ class C
{
public:
explicit C(std::string s)
: _s(s)
{
}
: _s(s)
{}
void foo();
private:
std::string _s;
Expand Down
5 changes: 2 additions & 3 deletions samples/passedByValue_1/good.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ class C
{
public:
explicit C(std::string s)
: _s(std::move(s))
{
}
: _s(std::move(s))
{}
void foo();
private:
std::string _s;
Expand Down
6 changes: 3 additions & 3 deletions test/cfg/boost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ void test_BOOST_FOREACH_3(std::vector<int> data)
void test_BOOST_FOREACH_4(std::vector<int> data)
{
BOOST_FOREACH(const int& i, data)
// cppcheck-suppress invalidContainerLoop
data.clear();
// cppcheck-suppress invalidContainerLoop
data.clear();
Comment on lines -148 to +149
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably add a scope here.

}

// Container returned as result of a function -> Be quiet
Expand All @@ -155,7 +155,7 @@ void test_BOOST_FOREACH_5()
{
std::set<int> data;
BOOST_FOREACH(const int& i, get_data())
data.insert(i);
data.insert(i);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should add a scope.

}

// Break after modification (#4788)
Expand Down
6 changes: 2 additions & 4 deletions test/cfg/googletest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,11 @@ namespace ExampleNamespace {

// syntaxError when TYPED_TEST is not known
TYPED_TEST (ExampleTypedTest, cppcheck_test)
{
}
{}

// syntaxError when TYPED_TEST_P is not known
TYPED_TEST_P (ExampleTypedTestP, cppcheck)
{
}
{}
}

TEST(ASSERT, ASSERT)
Expand Down
4 changes: 2 additions & 2 deletions test/cfg/kde.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class PluginWithoutMetaData : public QObject
public:
// Add a default arg to make sure we do not get an ambiguity compiler error
explicit PluginWithoutMetaData(const QObject *, const QVariantList &args = {})
: QObject()
: QObject()
{
Q_UNUSED(args)
};
Expand All @@ -64,7 +64,7 @@ class StaticSimplePluginClass : public QObject
public:
// Next to the assertion below, ensure that we have no ambiguity!
explicit StaticSimplePluginClass(QObject *parent, const QString &data = {})
: QObject(parent)
: QObject(parent)
{
// We have added a default arg, but KPluginFactory should still provide the valid metadata instead of the default one
data = QString("foo");
Expand Down
2 changes: 1 addition & 1 deletion test/cfg/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,7 @@ void* f_returns_NULL(void* arg)
void nullPointer_pthread_create() // #12396
{
pthread_t thread;
pthread_create(&thread, NULL, (void* (*)(void*))f_returns_NULL, NULL);
pthread_create(&thread, NULL, (void* (*)(void*)) f_returns_NULL, NULL);
}

void memleak_getaddrinfo() // #6994
Expand Down
2 changes: 1 addition & 1 deletion test/cfg/qt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -860,5 +860,5 @@ int qdateIsValid()
{
QDate qd(1,1,2025);
Q_ASSERT(qd.isValid()); // Should not warn here with assertWithSideEffect
return qd.month();
return qd.month();
}
10 changes: 5 additions & 5 deletions test/cfg/std.c
Original file line number Diff line number Diff line change
Expand Up @@ -3161,11 +3161,11 @@ void uninitvar_vwprintf(const wchar_t *Format, va_list Arg)
void nullPointer_bsearch(const void* key, const void* base, size_t num, size_t size)
{
// cppcheck-suppress nullPointer
(void)bsearch(NULL,base,num,size,(int (*)(const void*,const void*))strcmp);
(void)bsearch(NULL,base,num,size,(int (*)(const void*,const void*)) strcmp);
// cppcheck-suppress nullPointer
(void)bsearch(key,NULL,num,size,(int (*)(const void*,const void*))strcmp);
(void)bsearch(key,NULL,num,size,(int (*)(const void*,const void*)) strcmp);
// No warning is expected
(void)bsearch(key,base,num,size,(int (*)(const void*,const void*))strcmp);
(void)bsearch(key,base,num,size,(int (*)(const void*,const void*)) strcmp);
}

void uninitvar_bsearch(void)
Expand All @@ -3175,7 +3175,7 @@ void uninitvar_bsearch(void)
size_t num;
size_t size;
// cppcheck-suppress uninitvar
(void)bsearch(key,base,num,size,(int (*)(const void*,const void*))strcmp);
(void)bsearch(key,base,num,size,(int (*)(const void*,const void*)) strcmp);
}

void uninitvar_qsort(void)
Expand All @@ -3184,7 +3184,7 @@ void uninitvar_qsort(void)
size_t n;
size_t size;
// cppcheck-suppress uninitvar
(void)qsort(base,n,size, (int (*)(const void*,const void*))strcmp);
(void)qsort(base,n,size, (int (*)(const void*,const void*)) strcmp);
}

void uninitvar_putc(void)
Expand Down
20 changes: 10 additions & 10 deletions test/cfg/std.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,12 @@ int ignoredReturnValue_std_clamp(const int x)
void knownConditionTrueFalse_std_clamp(const int x)
{
// cppcheck-suppress knownConditionTrueFalse
if(std::clamp(-2, -1, 1) == -1){}
if (std::clamp(-2, -1, 1) == -1) {}
// cppcheck-suppress knownConditionTrueFalse
if(std::clamp(2, -1, 1) == 1){}
if (std::clamp(2, -1, 1) == 1) {}
// cppcheck-suppress knownConditionTrueFalse
if(std::clamp(0, -1, 1) == 0){}
if(std::clamp(x, 0, 2)){}
if (std::clamp(0, -1, 1) == 0) {}
if (std::clamp(x, 0, 2)) {}
}
#endif // __cpp_lib_clamp

Expand Down Expand Up @@ -3263,7 +3263,7 @@ void uninivar_bsearch(void)
size_t num;
size_t size;
// cppcheck-suppress [uninitvar, cstyleCast]
(void)std::bsearch(key,base,num,size,(int (*)(const void*,const void*))strcmp);
(void)std::bsearch(key,base,num,size,(int (*)(const void*,const void*)) strcmp);
}

void minsize_bsearch(const void* key, const void* base,
Expand All @@ -3272,11 +3272,11 @@ void minsize_bsearch(const void* key, const void* base,
{
const int Base[3] = {42, 43, 44};

(void)std::bsearch(key,Base,2,size,(int (*)(const void*,const void*))strcmp); // cppcheck-suppress cstyleCast
(void)std::bsearch(key,Base,3,size,(int (*)(const void*,const void*))strcmp); // cppcheck-suppress cstyleCast
(void)std::bsearch(key,Base,4,size,(int (*)(const void*,const void*))strcmp); // cppcheck-suppress cstyleCast
(void)std::bsearch(key,Base,2,size,(int (*)(const void*,const void*)) strcmp); // cppcheck-suppress cstyleCast
(void)std::bsearch(key,Base,3,size,(int (*)(const void*,const void*)) strcmp); // cppcheck-suppress cstyleCast
(void)std::bsearch(key,Base,4,size,(int (*)(const void*,const void*)) strcmp); // cppcheck-suppress cstyleCast

(void)std::bsearch(key,base,2,size,(int (*)(const void*,const void*))strcmp); // cppcheck-suppress cstyleCast
(void)std::bsearch(key,base,2,size,(int (*)(const void*,const void*)) strcmp); // cppcheck-suppress cstyleCast
}

void uninitvar_qsort(void)
Expand All @@ -3285,7 +3285,7 @@ void uninitvar_qsort(void)
size_t n;
size_t size;
// cppcheck-suppress uninitvar
(void)std::qsort(base,n,size, (int (*)(const void*,const void*))strcmp); // cppcheck-suppress cstyleCast
(void)std::qsort(base,n,size, (int (*)(const void*,const void*)) strcmp); // cppcheck-suppress cstyleCast
}

void uninitvar_stable_sort(std::vector<int>& v)
Expand Down
6 changes: 2 additions & 4 deletions test/cfg/windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1211,8 +1211,6 @@ void SEH_knownConditionTrueFalse() { // #8434
}

void SEH_unusedLabel() { // #13233
__try {
}
__finally {
}
__try {}
__finally {}
}