Skip to content

Commit 7301695

Browse files
committed
added test to demonstrate the issue
1 parent 19dd56f commit 7301695

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

.appveyor.yml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
os:
2-
- Visual Studio 2015
3-
- Visual Studio 2017
2+
- Visual Studio 2017
3+
- Visual Studio 2015
4+
5+
environment:
6+
matrix:
7+
- STD: 17
8+
- STD: 14
49

510
build_script:
611
- git submodule update --init --recursive
712
- mkdir build
813
- cd build
9-
- cmake ..
14+
- cmake -DCMAKE_CXX_STANDARD=%STD% -DCMAKE_CXX_STANDARD_REQUIRED=True ..
1015
- cmake --build .
1116
- C:\projects\function-ref\build\Debug\tests.exe
17+
18+
matrix:
19+
exclude:
20+
- os: Visual Studio 2015
21+
STD: 17

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ sudo: false
55

66
matrix:
77
include:
8+
- compiler: gcc
9+
addons:
10+
apt:
11+
sources:
12+
- ubuntu-toolchain-r-test
13+
packages:
14+
- g++-7
15+
env: COMPILER=g++-7 CXX_STANDARD=17
816
- compiler: gcc
917
addons:
1018
apt:

CMakeLists.txt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ include(add-tl)
2020
tl_add_library(function-ref ARCH_INDEPENDENT SOURCES
2121
include/tl/function_ref.hpp)
2222

23+
# make sure we see the C++ version, even in MSVC:
24+
# https://stackoverflow.com/questions/57102212/cannot-set-cplusplus-to-c17-standard-with-visual-studio-and-cmake
25+
if ((MSVC) AND (MSVC_VERSION GREATER_EQUAL 1914))
26+
target_compile_options(function-ref INTERFACE "/Zc:__cplusplus")
27+
endif()
28+
2329
# Prepare "Catch" library for other executables
2430
set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/test)
2531
add_library(Catch INTERFACE)
@@ -37,5 +43,8 @@ if(FUNCTION_REF_ENABLE_TESTS)
3743

3844
target_link_libraries(tests Catch function-ref)
3945

40-
set_property(TARGET tests PROPERTY CXX_STANDARD 14)
46+
message(STATUS "CMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}")
47+
if(NOT CMAKE_CXX_STANDARD)
48+
set_property(TARGET tests PROPERTY CXX_STANDARD 14)
49+
endif()
4150
endif()

tests/issues.cpp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,20 @@ TEST_CASE("Issue #10") {
2929
int z = 12;
3030
auto f = [&](const std::vector<int> i) { return i[0] * z; };
3131
foo(f);
32-
}
32+
}
33+
34+
#if __cplusplus >= 201703
35+
struct NonCopyNonMove {
36+
NonCopyNonMove() = default;
37+
NonCopyNonMove(const NonCopyNonMove &) = delete;
38+
NonCopyNonMove(NonCopyNonMove &&) = delete;
39+
};
40+
41+
TEST_CASE("Issue #20") {
42+
auto f = []() { return NonCopyNonMove(); };
43+
auto fr = tl::function_ref<NonCopyNonMove()>(f);
44+
45+
// silence warnings
46+
(void)fr;
47+
}
48+
#endif

0 commit comments

Comments
 (0)