Skip to content

Commit 62ee8fd

Browse files
Test cpp_dummy_build in pedantic mode
In public headers, we want to avoid things that are not standard C++, including features that GCC and Clang support as extensions, such as flexible array members. So compile with `-pedantic`. Non-regression for Mbed-TLS#9020. Signed-off-by: Gilles Peskine <[email protected]>
1 parent b0cc2ad commit 62ee8fd

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

CMakeLists.txt

+9
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,15 @@ if(MBEDTLS_FATAL_WARNINGS)
281281
endif(CMAKE_COMPILER_IS_IAR)
282282
endif(MBEDTLS_FATAL_WARNINGS)
283283

284+
if(CMAKE_BUILD_TYPE STREQUAL "Check" AND TEST_CPP)
285+
set(CMAKE_CXX_STANDARD 11)
286+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
287+
set(CMAKE_CXX_EXTENSIONS OFF)
288+
if(CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNU)
289+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
290+
endif()
291+
endif()
292+
284293
if(CMAKE_BUILD_TYPE STREQUAL "Coverage")
285294
if(CMAKE_COMPILER_IS_GNU OR CMAKE_COMPILER_IS_CLANG)
286295
set(CMAKE_SHARED_LINKER_FLAGS "--coverage")

scripts/common.make

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ include $(MBEDTLS_PATH)/framework/exported.make
2020

2121
CFLAGS ?= -O2
2222
WARNING_CFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
23-
WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral
23+
WARNING_CXXFLAGS ?= -Wall -Wextra -Wformat=2 -Wno-format-nonliteral -std=c++11 -pedantic
2424
LDFLAGS ?=
2525

2626
LOCAL_CFLAGS = $(WARNING_CFLAGS) -I$(MBEDTLS_TEST_PATH)/include \

tests/scripts/components-build-system.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
component_test_make_shared () {
1313
msg "build/test: make shared" # ~ 40s
14-
make SHARED=1 all check
14+
make SHARED=1 TEST_CPP=1 all check
1515
ldd programs/util/strerror | grep libmbedcrypto
1616
programs/test/dlopen_demo.sh
1717
}
@@ -65,7 +65,7 @@ component_test_cmake_out_of_source () {
6565
mkdir "$OUT_OF_SOURCE_DIR"
6666
cd "$OUT_OF_SOURCE_DIR"
6767
# Note: Explicitly generate files as these are turned off in releases
68-
cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON "$MBEDTLS_ROOT_DIR"
68+
cmake -D CMAKE_BUILD_TYPE:String=Check -D GEN_FILES=ON _D TEST_CPP=1 "$MBEDTLS_ROOT_DIR"
6969
make
7070

7171
msg "test: cmake 'out-of-source' build"

0 commit comments

Comments
 (0)