From 021542df3b724030997cd4c83de5127d7e937b59 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Mon, 4 Sep 2023 23:57:25 +0200 Subject: [PATCH 1/7] New commit --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e49c66e..cc9a187 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,6 +17,6 @@ jobs: if: always() uses: JacobDomagala/CompileResult@master with: - comment_title: UBUNTU COMPILE RESULT + comment_title: COMPILE RESULT debug_output: true compile_result_file: ${{runner.workspace}}/build/output.txt From 8a03d67487f92034d496b94ab7d24517529b9b46 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Mon, 4 Sep 2023 23:59:43 +0200 Subject: [PATCH 2/7] New warning --- source.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source.cpp b/source.cpp index 7b81843..909c679 100644 --- a/source.cpp +++ b/source.cpp @@ -6,6 +6,6 @@ void some_func(){ int main(){ float float_val = 20.0; - + int k; return "some_string"; } From 551c403b969e92d0707dc2cba705e4e13d9a5286 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Tue, 5 Sep 2023 00:02:53 +0200 Subject: [PATCH 3/7] Fix --- .github/workflows/test.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cc9a187..c8f10a9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,9 +8,10 @@ jobs: steps: - uses: actions/checkout@v3 - name: Build - working-directory: ${{runner.workspace}}/build/some/right shell: bash run: | + mkdir -p ${{runner.workspace}}/build/some/right + cd ${{runner.workspace}}/build/some/right cmake $GITHUB_WORKSPACE cmake --build . 2> >(tee "output.txt") - name: Post PR comment for warnings/errors From 8e2917b7f0492f80793008cce131c51aedca2e63 Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Tue, 5 Sep 2023 00:05:25 +0200 Subject: [PATCH 4/7] Check matrix --- .github/workflows/test.yml | 18 +++++++++++---- CMakeLists.txt | 47 +++++++++++++++++++++++++++++++++++++- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c8f10a9..229c9a1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,23 +1,31 @@ -name: Build on Ubuntu +name: Build on Multiple OS on: [pull_request] jobs: Compile: - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, windows-latest] steps: - uses: actions/checkout@v3 + + - name: Create Working Directory + run: mkdir -p ${{runner.workspace}}/build + - name: Build + working-directory: ${{runner.workspace}}/build shell: bash run: | - mkdir -p ${{runner.workspace}}/build/some/right - cd ${{runner.workspace}}/build/some/right cmake $GITHUB_WORKSPACE cmake --build . 2> >(tee "output.txt") + - name: Post PR comment for warnings/errors if: always() uses: JacobDomagala/CompileResult@master with: - comment_title: COMPILE RESULT + comment_title: COMPILE RESULT (${{ matrix.os }}) debug_output: true compile_result_file: ${{runner.workspace}}/build/output.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 68b8ae3..e002896 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,32 @@ cmake_minimum_required(VERSION 3.13) project(Test) +set(MSVC_WARNINGS +/W4 # Baseline reasonable warnings +/w14242 # 'identifier': conversion from 'type1' to 'type1', possible loss of data +/w14254 # 'operator': conversion from 'type1:field_bits' to 'type2:field_bits', possible loss of data +/w14263 # 'function': member function does not override any base class virtual member function +/w14265 # 'classname': class has virtual functions, but destructor is not virtual instances of this class may not + # be destructed correctly +/w14287 # 'operator': unsigned/negative constant mismatch +/we4289 # nonstandard extension used: 'variable': loop control variable declared in the for-loop is used outside + # the for-loop scope +/w14296 # 'operator': expression is always 'boolean_value' +/w14311 # 'variable': pointer truncation from 'type1' to 'type2' +/w14545 # expression before comma evaluates to a function which is missing an argument list +/w14546 # function call before comma missing argument list +/w14547 # 'operator': operator before comma has no effect; expected operator with side-effect +/w14549 # 'operator': operator before comma has no effect; did you intend 'operator'? +/w14555 # expression has no effect; expected expression with side- effect +/w14619 # pragma warning: there is no warning number 'number' +/w14640 # Enable warning on thread un-safe static member initialization +/w14826 # Conversion from 'type1' to 'type_2' is sign-extended. This may cause unexpected runtime behavior. +/w14905 # wide string literal cast to 'LPSTR' +/w14906 # string literal cast to 'LPWSTR' +/w14928 # illegal copy-initialization; more than one user-defined conversion has been implicitly applied +/permissive- # standards conformance mode for MSVC compiler. +) + set(CLANG_WARNINGS -Wall -Wextra # reasonable and standard @@ -20,5 +46,24 @@ set(CLANG_WARNINGS -Wformat=2 # warn on security issues around functions that format output (ie printf) ) +set(GCC_WARNINGS + ${CLANG_WARNINGS} + -Wmisleading-indentation # warn if indentation implies blocks where blocks do not exist + -Wduplicated-cond # warn if if / else chain has duplicated conditions + -Wduplicated-branches # warn if if / else branches have duplicated code + -Wlogical-op # warn about logical operations being used where bitwise were probably wanted + -Wuseless-cast # warn if you perform a cast to the same type +) + +if(MSVC) +set(TARGET_WARNINGS ${MSVC_WARNINGS}) +elseif(CMAKE_CXX_COMPILER_ID MATCHES ".*Clang") +set(TARGET_WARNINGS ${CLANG_WARNINGS}) +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") +set(TARGET_WARNINGS ${GCC_WARNINGS}) +else() +message(AUTHOR_WARNING "No compiler warnings set for '${CMAKE_CXX_COMPILER_ID}' compiler.") +endif() + add_executable(TestApp source.cpp) -target_compile_options(TestApp PUBLIC ${CLANG_WARNINGS}) +target_compile_options(TestApp PUBLIC ${TARGET_WARNINGS}) From 7c3d4b18354646b1dd481345fe5ef96cf662638e Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Fri, 13 Jun 2025 12:58:12 +0200 Subject: [PATCH 5/7] Update branch --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 229c9a1..8eeaed0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: - name: Post PR comment for warnings/errors if: always() - uses: JacobDomagala/CompileResult@master + uses: JacobDomagala/CompileResult@31-warnings-with-relative-paths-not-parsed with: comment_title: COMPILE RESULT (${{ matrix.os }}) debug_output: true From d20540002cd2a511bf96ca94b20ed20774d66f8e Mon Sep 17 00:00:00 2001 From: Jacob Domagala Date: Fri, 13 Jun 2025 13:02:14 +0200 Subject: [PATCH 6/7] Add new file --- .github/workflows/test.yml | 10 ++++++++++ result_gnu.txt | 41 ++++++++++++++++++++++++++++++++++++++ result_msvc.txt | 13 ++++++++++++ src/another.cpp | 19 ++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 result_gnu.txt create mode 100644 result_msvc.txt create mode 100644 src/another.cpp diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8eeaed0..65f81f2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -28,4 +28,14 @@ jobs: with: comment_title: COMPILE RESULT (${{ matrix.os }}) debug_output: true + compiler: ${{ matrix.os == 'windows-latest' && 'MSVC' || 'GNU' }} compile_result_file: ${{runner.workspace}}/build/output.txt + + - name: Post PR comment for warnings/errors (edited) + if: always() + uses: JacobDomagala/CompileResult@31-warnings-with-relative-paths-not-parsed + with: + comment_title: COMPILE RESULT (${{ matrix.os }}) edited + debug_output: true + compiler: ${{ matrix.os == 'windows-latest' && 'MSVC' || 'GNU' }} + compile_result_file: ${{ matrix.os == 'windows-latest' && 'result_msvc.txt' || 'result_gnu.txt' }} diff --git a/result_gnu.txt b/result_gnu.txt new file mode 100644 index 0000000..e80f55c --- /dev/null +++ b/result_gnu.txt @@ -0,0 +1,41 @@ +src/another.cpp: In function ‘void foo(int)’: +src/another.cpp:4:9: warning: unused variable ‘unused’ [-Wunused-variable] + 4 | int unused; + | ^~~~~~ +src/another.cpp:5:9: warning: suggest parentheses around assignment used as truth value [-Wparentheses] + 5 | if (x = 0) { + | ^ + +src/another.cpp: In function ‘int main()’: +src/another.cpp:11:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare] + 11 | for (int i = 10; i >= 0; --i) { + | ~~^~~ +src/another.cpp:13:12: warning: overflow in conversion from ‘int’ to ‘char’ changes value from ‘300’ to ‘44’ [-Woverflow] + 13 | char c = 300; + | ^ + +src/another.cpp:14:9: warning: conversion from ‘char’ to ‘int’ may change value [-Wconversion] + 14 | foo(c); + | ^ +/home/runner/work/TestRepo/TestRepo/source.cpp: In function ‘void some_func()’: +/home/runner/work/TestRepo/TestRepo/source.cpp:4:9: warning: unused variable ‘unused_var’ [-Wunused-variable] + 4 | int unused_var = 10; + | ^~~~~~~~~~ +/home/runner/work/TestRepo/TestRepo/source.cpp: In function ‘int main()’: +/home/runner/work/TestRepo/TestRepo/source.cpp:10:12: error: invalid conversion from ‘const char*’ to ‘int’ [-fpermissive] + 10 | return "some_string"; + | ^~~~~~~~~~~~~ + | | + | const char* +/home/runner/work/TestRepo/TestRepo/source.cpp:8:11: warning: unused variable ‘float_val’ [-Wunused-variable] + 8 | float float_val = 20.0; + | ^~~~~~~~~ +/home/runner/work/TestRepo/TestRepo/source.cpp:9:9: warning: unused variable ‘k’ [-Wunused-variable] + 9 | int k; + | ^ +invalid_source.cpp:8:11: warning: unused variable ‘float_val’ [-Wunused-variable] + 8 | float float_val = 20.0; + | ^~~~~~~~~ +invalid_source.cpp:9:9: warning: unused variable ‘k’ [-Wunused-variable] + 9 | int k; + | ^ diff --git a/result_msvc.txt b/result_msvc.txt new file mode 100644 index 0000000..4903da9 --- /dev/null +++ b/result_msvc.txt @@ -0,0 +1,13 @@ +src\another.cpp(4): warning C4101: 'unused': unreferenced local variable +src\another.cpp(5): warning C4552: '=': operator has no effect; did you intend to compare? +src\another.cpp(11): warning C4018: '>=': signed/unsigned mismatch +src\another.cpp(13): warning C4309: 'initializing': truncation of constant value +src\another.cpp(14): warning C4244: 'argument': conversion from 'char' to 'int', possible loss of data + +C:\a_work\TestRepo\TestRepo\source.cpp(4): warning C4101: 'unused_var': unreferenced local variable +C:\a_work\TestRepo\TestRepo\source.cpp(8): warning C4101: 'float_val': unreferenced local variable +C:\a_work\TestRepo\TestRepo\source.cpp(9): warning C4101: 'k': unreferenced local variable +C:\a_work\TestRepo\TestRepo\source.cpp(10): error C2440: 'return': cannot convert from 'const char *' to 'int' + +invalid_source.cpp(8): warning C4101: 'float_val': unreferenced local variable +invalid_source.cpp(9): warning C4101: 'k': unreferenced local variable diff --git a/src/another.cpp b/src/another.cpp new file mode 100644 index 0000000..5e005a1 --- /dev/null +++ b/src/another.cpp @@ -0,0 +1,19 @@ + +#include + +void foo(int x) { + int unused; // -Wunused-variable + if (x = 0) { // -Wparentheses (assignment in condition) + std::cout << "never\n"; + } +} + +int main() { + unsigned int u = 0; + for (int i = 10; i >= 0; --i) { // -Wsign-compare + u += i; + } + char c = 300; // -Woverflow / -Wconversion + foo(c); // -Wconversion + return 0; +} From f2cbe5828a1efc5f8b460148c3e1faf1eda60de1 Mon Sep 17 00:00:00 2001 From: JacobDomagala Date: Fri, 13 Jun 2025 21:50:09 +0200 Subject: [PATCH 7/7] Update pipe --- .github/workflows/test.yml | 2 +- result_msvc.txt | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 65f81f2..ced5b34 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: shell: bash run: | cmake $GITHUB_WORKSPACE - cmake --build . 2> >(tee "output.txt") + cmake --build . 2>&1 | tee "output.txt" - name: Post PR comment for warnings/errors if: always() diff --git a/result_msvc.txt b/result_msvc.txt index 4903da9..faecff2 100644 --- a/result_msvc.txt +++ b/result_msvc.txt @@ -1,13 +1,13 @@ -src\another.cpp(4): warning C4101: 'unused': unreferenced local variable -src\another.cpp(5): warning C4552: '=': operator has no effect; did you intend to compare? -src\another.cpp(11): warning C4018: '>=': signed/unsigned mismatch -src\another.cpp(13): warning C4309: 'initializing': truncation of constant value -src\another.cpp(14): warning C4244: 'argument': conversion from 'char' to 'int', possible loss of data +src\another.cpp(5): warning C4101: 'unused': unreferenced local variable +src\another.cpp(6): warning C4552: '=': operator has no effect; did you intend to compare? +src\another.cpp(13): warning C4018: '>=': signed/unsigned mismatch +src\another.cpp(16): warning C4309: 'initializing': truncation of constant value +src\another.cpp(17): warning C4244: 'argument': conversion from 'char' to 'int', possible loss of data -C:\a_work\TestRepo\TestRepo\source.cpp(4): warning C4101: 'unused_var': unreferenced local variable -C:\a_work\TestRepo\TestRepo\source.cpp(8): warning C4101: 'float_val': unreferenced local variable -C:\a_work\TestRepo\TestRepo\source.cpp(9): warning C4101: 'k': unreferenced local variable -C:\a_work\TestRepo\TestRepo\source.cpp(10): error C2440: 'return': cannot convert from 'const char *' to 'int' +C:\a\TestRepo\TestRepo\source.cpp(4): warning C4101: 'unused_var': unreferenced local variable +C:\a\TestRepo\TestRepo\source.cpp(8): warning C4101: 'float_val': unreferenced local variable +C:\a\TestRepo\TestRepo\source.cpp(9): warning C4101: 'k': unreferenced local variable +C:\a\TestRepo\TestRepo\source.cpp(10): error C2440: 'return': cannot convert from 'const char *' to 'int' invalid_source.cpp(8): warning C4101: 'float_val': unreferenced local variable invalid_source.cpp(9): warning C4101: 'k': unreferenced local variable