Skip to content

Commit a766d22

Browse files
authored
enabled and cleaned up some compiler warning flags (#551)
1 parent 318a37b commit a766d22

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

CMakeLists.txt

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,56 +19,60 @@ function(add_compile_options_safe FLAG)
1919
endif()
2020
endfunction()
2121

22-
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
22+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
2323
add_compile_options(-pedantic)
24+
2425
add_compile_options(-Wall)
2526
add_compile_options(-Wextra)
2627
add_compile_options(-Wcast-qual) # Cast for removing type qualifiers
2728
add_compile_options(-Wfloat-equal) # Floating values used in equality comparisons
2829
add_compile_options(-Wmissing-declarations) # If a global function is defined without a previous declaration
2930
add_compile_options(-Wmissing-format-attribute) #
30-
add_compile_options(-Wno-long-long)
3131
add_compile_options(-Wpacked) #
3232
add_compile_options(-Wredundant-decls) # if anything is declared more than once in the same scope
3333
add_compile_options(-Wundef)
34-
add_compile_options(-Wno-missing-braces)
35-
add_compile_options(-Wno-sign-compare)
36-
add_compile_options(-Wno-multichar)
3734
add_compile_options(-Woverloaded-virtual) # when a function declaration hides virtual functions from a base class
3835

3936
add_compile_options(-Wsuggest-attribute=noreturn)
4037
add_compile_options_safe(-Wuseless-cast)
41-
elseif (CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
38+
39+
# we are not interested in these
40+
set_source_files_properties(test.cpp PROPERTIES COMPILE_FLAGS -Wno-multichar)
41+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
4242
add_compile_definitions(_CRT_SECURE_NO_WARNINGS)
43-
# TODO: bump warning level
44-
#add_compile_options(/W4) # Warning Level
45-
# TODO: enable warning
43+
44+
add_compile_options(/W4) # Warning Level
45+
46+
add_compile_options(/wd4127) # warning C4127: conditional expression is constant
47+
add_compile_options(/wd4244) # warning C4244: 'x': conversion from 'int' to 'char', possible loss of data
4648
add_compile_options(/wd4267) # warning C4267: '...': conversion from 'size_t' to 'unsigned int', possible loss of data
49+
add_compile_options(/wd4706) # warning C4706: assignment within conditional expression
4750
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
4851
add_compile_options(-Weverything)
52+
4953
# no need for c++98 compatibility
5054
add_compile_options(-Wno-c++98-compat-pedantic)
51-
# these are not really fixable
55+
56+
# these are not really fixable until newer standards
5257
add_compile_options(-Wno-exit-time-destructors)
5358
add_compile_options(-Wno-global-constructors)
5459
add_compile_options(-Wno-weak-vtables)
5560
add_compile_options_safe(-Wno-unsafe-buffer-usage)
5661
add_compile_options_safe(-Wno-nrvo)
57-
# we are not interested in these
58-
add_compile_options(-Wno-multichar)
59-
add_compile_options(-Wno-four-char-constants)
60-
# ignore C++11-specific warning
61-
add_compile_options(-Wno-suggest-override)
62-
add_compile_options(-Wno-suggest-destructor-override)
62+
6363
# contradicts -Wcovered-switch-default
6464
add_compile_options(-Wno-switch-default)
65+
6566
# TODO: fix these?
6667
add_compile_options(-Wno-padded)
6768
add_compile_options(-Wno-sign-conversion)
6869
add_compile_options(-Wno-implicit-int-conversion)
6970
add_compile_options(-Wno-shorten-64-to-32)
7071
add_compile_options(-Wno-shadow-field-in-constructor)
7172

73+
# we are not interested in these
74+
set_source_files_properties(test.cpp PROPERTIES COMPILE_FLAGS "-Wno-multichar -Wno-four-char-constants")
75+
7276
if (CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 14 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 14)
7377
# TODO: verify this regression still exists in clang-15
7478
if (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
all: testrunner simplecpp
22

33
CPPFLAGS ?=
4-
CXXFLAGS = -Wall -Wextra -pedantic -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wundef -Wno-multichar -Wold-style-cast -std=c++11 -g $(CXXOPTS)
4+
CXXFLAGS = -Wall -Wextra -pedantic -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wpacked -Wredundant-decls -Wundef -Woverloaded-virtual -std=c++11 -g $(CXXOPTS)
55
LDFLAGS = -g $(LDOPTS)
66

77
# Define test source dir macro for compilation (preprocessor flags)
88
TEST_CPPFLAGS = -DSIMPLECPP_TEST_SOURCE_DIR=\"$(CURDIR)\"
99

1010
# Only test.o gets the define
1111
test.o: CPPFLAGS += $(TEST_CPPFLAGS)
12+
test.o: CXXFLAGS += -Wno-multichar
1213

1314
%.o: %.cpp simplecpp.h
1415
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $<

0 commit comments

Comments
 (0)