Skip to content

Commit a9707c3

Browse files
authored
Merge pull request #133 from mapbox/Werror
Starts building with -Werror
2 parents 1891917 + a80beaa commit a9707c3

File tree

3 files changed

+60
-23
lines changed

3 files changed

+60
-23
lines changed

.travis.yml

+10-2
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ matrix:
7676
addons:
7777
apt:
7878
sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5' ]
79-
packages: [ 'clang-3.5' ]
79+
packages: [ 'clang-3.5', 'libstdc++-4.9-dev' ]
8080
- os: linux
8181
compiler: "clang36"
8282
env: CXX=clang++-3.6
@@ -93,7 +93,7 @@ matrix:
9393
packages: [ 'clang-3.7' ]
9494
- os: linux
9595
compiler: "gcc47"
96-
env: CXX=g++-4.7
96+
env: CXX=g++-4.7 CXXFLAGS="-Wno-parentheses"
9797
addons:
9898
apt:
9999
sources: [ 'ubuntu-toolchain-r-test' ]
@@ -139,6 +139,14 @@ install:
139139
fi
140140

141141
script:
142+
# Build in Release
143+
- make test
144+
- make bench
145+
- make sizes
146+
- scripts/run_compilation_failure_tests.sh
147+
- make clean;
148+
# Build in Debug
149+
- export BUILDTYPE=Debug
142150
- make test
143151
- make bench
144152
- make sizes

Makefile

+48-19
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,42 @@ BOOST_VERSION = 1.62.0
44
CXX := $(CXX)
55
CXX_STD ?= c++11
66

7-
BOOST_FLAGS = `$(MASON) cflags boost $(BOOST_VERSION)`
7+
BOOST_ROOT = $(shell $(MASON) prefix boost $(BOOST_VERSION))
8+
BOOST_FLAGS = -isystem $(BOOST_ROOT)/include/
89
RELEASE_FLAGS = -O3 -DNDEBUG -march=native -DSINGLE_THREADED -fvisibility-inlines-hidden -fvisibility=hidden
9-
DEBUG_FLAGS = -O0 -g -DDEBUG -fno-inline-functions -fno-omit-frame-pointer
10-
COMMON_FLAGS = -Wall -pedantic -Wextra -Wsign-compare -Wsign-conversion -Wshadow -Wunused-parameter -std=$(CXX_STD)
10+
DEBUG_FLAGS = -O0 -g -DDEBUG -fno-inline-functions -fno-omit-frame-pointer -fPIE -D_FORTIFY_SOURCE=2 -fwrapv -Wformat -Wformat-security
11+
COMMON_FLAGS = -std=$(CXX_STD)
12+
13+
WARNING_FLAGS = -Wall -Werror -pedantic -Wextra -Wsign-compare -Wsign-conversion -Wshadow -Wunused-parameter
14+
CLANG_WARNING_FLAGS = -Wno-unsequenced -Wno-c++98-compat -Wno-c++98-compat-pedantic -Wno-exit-time-destructors
15+
ifneq (,$(findstring clang,$(CXX)))
16+
WARNING_FLAGS += $(CLANG_WARNING_FLAGS)
17+
endif
18+
19+
COMMON_FLAGS += $(WARNING_FLAGS)
20+
1121
CXXFLAGS := $(CXXFLAGS)
1222
LDFLAGS := $(LDFLAGS)
1323

24+
export BUILDTYPE ?= Release
25+
26+
OS := $(shell uname -s)
27+
ifeq ($(OS), Linux)
28+
EXTRA_FLAGS = -pthread
29+
endif
30+
ifeq ($(OS), Darwin)
31+
EXTRA_FLAGS = -mmacosx-version-min=10.8
32+
endif
33+
34+
35+
ifeq ($(BUILDTYPE),Release)
36+
FINAL_CXXFLAGS := $(COMMON_FLAGS) $(RELEASE_FLAGS) $(CXXFLAGS) $(EXTRA_FLAGS)
37+
else
38+
FINAL_CXXFLAGS := $(COMMON_FLAGS) $(DEBUG_FLAGS) $(CXXFLAGS) $(EXTRA_FLAGS)
39+
endif
40+
41+
42+
1443
ALL_HEADERS = $(shell find include/mapbox/ '(' -name '*.hpp' ')')
1544

1645
all: out/bench-variant out/unique_ptr_test out/unique_ptr_test out/recursive_wrapper_test out/binary_visitor_test out/lambda_overload_test out/hashable_test
@@ -31,31 +60,31 @@ gyp: ./deps/gyp
3160

3261
out/bench-variant-debug: Makefile mason_packages/headers/boost test/bench_variant.cpp
3362
mkdir -p ./out
34-
$(CXX) -o out/bench-variant-debug test/bench_variant.cpp -I./include -Itest/include -pthreads $(DEBUG_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
63+
$(CXX) -o out/bench-variant-debug test/bench_variant.cpp -I./include -isystem test/include $(FINAL_CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
3564

3665
out/bench-variant: Makefile mason_packages/headers/boost test/bench_variant.cpp
3766
mkdir -p ./out
38-
$(CXX) -o out/bench-variant test/bench_variant.cpp -I./include -Itest/include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
67+
$(CXX) -o out/bench-variant test/bench_variant.cpp -I./include -isystem test/include $(FINAL_CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
3968

4069
out/unique_ptr_test: Makefile mason_packages/headers/boost test/unique_ptr_test.cpp
4170
mkdir -p ./out
42-
$(CXX) -o out/unique_ptr_test test/unique_ptr_test.cpp -I./include -Itest/include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
71+
$(CXX) -o out/unique_ptr_test test/unique_ptr_test.cpp -I./include -isystem test/include $(FINAL_CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
4372

4473
out/recursive_wrapper_test: Makefile mason_packages/headers/boost test/recursive_wrapper_test.cpp
4574
mkdir -p ./out
46-
$(CXX) -o out/recursive_wrapper_test test/recursive_wrapper_test.cpp -I./include -Itest/include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
75+
$(CXX) -o out/recursive_wrapper_test test/recursive_wrapper_test.cpp -I./include -isystem test/include $(FINAL_CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
4776

4877
out/binary_visitor_test: Makefile mason_packages/headers/boost test/binary_visitor_test.cpp
4978
mkdir -p ./out
50-
$(CXX) -o out/binary_visitor_test test/binary_visitor_test.cpp -I./include -Itest/include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
79+
$(CXX) -o out/binary_visitor_test test/binary_visitor_test.cpp -I./include -isystem test/include $(FINAL_CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
5180

5281
out/lambda_overload_test: Makefile mason_packages/headers/boost test/lambda_overload_test.cpp
5382
mkdir -p ./out
54-
$(CXX) -o out/lambda_overload_test test/lambda_overload_test.cpp -I./include -Itest/include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
83+
$(CXX) -o out/lambda_overload_test test/lambda_overload_test.cpp -I./include -isystem test/include $(FINAL_CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
5584

5685
out/hashable_test: Makefile mason_packages/headers/boost test/hashable_test.cpp
5786
mkdir -p ./out
58-
$(CXX) -o out/hashable_test test/hashable_test.cpp -I./include -Itest/include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
87+
$(CXX) -o out/hashable_test test/hashable_test.cpp -I./include -isystem test/include $(FINAL_CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS)
5988

6089
bench: out/bench-variant out/unique_ptr_test out/unique_ptr_test out/recursive_wrapper_test out/binary_visitor_test
6190
./out/bench-variant 100000
@@ -65,11 +94,11 @@ bench: out/bench-variant out/unique_ptr_test out/unique_ptr_test out/recursive_w
6594

6695
out/unit.o: Makefile test/unit.cpp
6796
mkdir -p ./out
68-
$(CXX) -c -o $@ test/unit.cpp -Itest/include $(DEBUG_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS)
97+
$(CXX) -c -o $@ test/unit.cpp -isystem test/include $(FINAL_CXXFLAGS)
6998

7099
out/%.o: test/t/%.cpp Makefile $(ALL_HEADERS)
71100
mkdir -p ./out
72-
$(CXX) -c -o $@ $< -Iinclude -Itest/include $(DEBUG_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS)
101+
$(CXX) -c -o $@ $< -Iinclude -isystem test/include $(FINAL_CXXFLAGS)
73102

74103
out/unit: out/unit.o out/binary_visitor_1.o out/binary_visitor_2.o out/binary_visitor_3.o out/binary_visitor_4.o out/binary_visitor_5.o out/binary_visitor_6.o out/issue21.o out/issue122.o out/mutating_visitor.o out/optional.o out/recursive_wrapper.o out/sizeof.o out/unary_visitor.o out/variant.o
75104
mkdir -p ./out
@@ -80,14 +109,14 @@ test: out/unit
80109

81110
coverage:
82111
mkdir -p ./out
83-
$(CXX) -o out/cov-test --coverage test/unit.cpp test/t/*.cpp -I./include -Itest/include $(DEBUG_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(LDFLAGS)
112+
$(CXX) -o out/cov-test --coverage test/unit.cpp test/t/*.cpp -I./include -isystem test/include $(FINAL_CXXFLAGS) $(LDFLAGS)
84113

85114
sizes: Makefile
86115
mkdir -p ./out
87-
@$(CXX) -o ./out/our_variant_hello_world.out include/mapbox/variant.hpp -I./include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) && du -h ./out/our_variant_hello_world.out
88-
@$(CXX) -o ./out/boost_variant_hello_world.out `$(MASON) prefix boost $(BOOST_VERSION)`/include/boost/variant.hpp -I./include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(BOOST_FLAGS) && du -h ./out/boost_variant_hello_world.out
89-
@$(CXX) -o ./out/our_variant_hello_world ./test/our_variant_hello_world.cpp -I./include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) && du -h ./out/our_variant_hello_world
90-
@$(CXX) -o ./out/boost_variant_hello_world ./test/boost_variant_hello_world.cpp -I./include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(BOOST_FLAGS) && du -h ./out/boost_variant_hello_world
116+
@$(CXX) -o ./out/our_variant_hello_world.out include/mapbox/variant.hpp -I./include $(FINAL_CXXFLAGS) && du -h ./out/our_variant_hello_world.out
117+
@$(CXX) -o ./out/boost_variant_hello_world.out $(BOOST_ROOT)/include/boost/variant.hpp -I./include $(FINAL_CXXFLAGS) $(BOOST_FLAGS) && du -h ./out/boost_variant_hello_world.out
118+
@$(CXX) -o ./out/our_variant_hello_world ./test/our_variant_hello_world.cpp -I./include $(FINAL_CXXFLAGS) && du -h ./out/our_variant_hello_world
119+
@$(CXX) -o ./out/boost_variant_hello_world ./test/boost_variant_hello_world.cpp -I./include $(FINAL_CXXFLAGS) $(BOOST_FLAGS) && du -h ./out/boost_variant_hello_world
91120

92121
profile: out/bench-variant-debug
93122
mkdir -p profiling/
@@ -104,8 +133,8 @@ clean:
104133
rm -f *.gcda *.gcno
105134

106135
pgo: out Makefile
107-
$(CXX) -o out/bench-variant test/bench_variant.cpp -I./include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS) -pg -fprofile-generate
136+
$(CXX) -o out/bench-variant test/bench_variant.cpp -I./include $(FINAL_CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS) -pg -fprofile-generate
108137
./test-variant 500000 >/dev/null 2>/dev/null
109-
$(CXX) -o out/bench-variant test/bench_variant.cpp -I./include $(RELEASE_FLAGS) $(COMMON_FLAGS) $(CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS) -fprofile-use
138+
$(CXX) -o out/bench-variant test/bench_variant.cpp -I./include $(FINAL_CXXFLAGS) $(LDFLAGS) $(BOOST_FLAGS) -fprofile-use
110139

111140
.PHONY: sizes test

test/t/binary_visitor_impl.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ struct swap_visitor
160160
{
161161
using T = typename std::common_type<A, B>::type;
162162
T tmp = a;
163-
a = b;
164-
b = tmp;
163+
a = static_cast<A>(b);
164+
b = static_cast<B>(tmp);
165165
}
166166
};
167167

0 commit comments

Comments
 (0)