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
31 changes: 25 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,41 @@
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/some/right
working-directory: ${{runner.workspace}}/build
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()
uses: JacobDomagala/CompileResult@master
uses: JacobDomagala/CompileResult@31-warnings-with-relative-paths-not-parsed
with:
comment_title: UBUNTU COMPILE RESULT
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' }}
47 changes: 46 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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})
41 changes: 41 additions & 0 deletions result_gnu.txt
Original file line number Diff line number Diff line change
@@ -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;
| ^
13 changes: 13 additions & 0 deletions result_msvc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
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\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
2 changes: 1 addition & 1 deletion source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ void some_func(){

int main(){
float float_val = 20.0;

int k;
return "some_string";
}
19 changes: 19 additions & 0 deletions src/another.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

#include <iostream>

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;
}