Skip to content

Commit ddc8da8

Browse files
committed
test.cpp: added compilation test for safe api [skip ci]
1 parent 7c56624 commit ddc8da8

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

.github/workflows/CI-unixish.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ jobs:
5555
run: |
5656
python3 -m pytest integration_test.py -vv
5757
58+
- name: make testrunner (c++17)
59+
run: make -j$(nproc) testrunner CXXOPT="-std=c++17"
60+
61+
- name: make testrunner (c++20)
62+
run: make -j$(nproc) testrunner CXXOPT="-std=c++20"
63+
5864
- name: Run CMake
5965
run: |
6066
cmake -S . -B cmake.output

test.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3125,6 +3125,43 @@ static void preprocess_files()
31253125
}
31263126
}
31273127

3128+
static void safe_api()
3129+
{
3130+
#if defined(__cpp_lib_string_view) || defined(__cpp_lib_span)
3131+
std::vector<std::string> filenames;
3132+
# if defined(__cpp_lib_string_view)
3133+
{
3134+
const char input[] = "code";
3135+
const std::string_view sv = input;
3136+
// std::string_view can be implicitly converted into a std::span
3137+
simplecpp::TokenList(sv,filenames,"");
3138+
}
3139+
# endif
3140+
# ifdef __cpp_lib_span
3141+
{
3142+
char input[] = "code";
3143+
const std::span<char, 5> sp = input;
3144+
simplecpp::TokenList(sp,filenames,"");
3145+
}
3146+
{
3147+
const char input[] = "code";
3148+
const std::span<const char, 5> sp = input;
3149+
simplecpp::TokenList(sp,filenames,"");
3150+
}
3151+
{
3152+
unsigned char input[] = "code";
3153+
const std::span<unsigned char, 5> sp = input;
3154+
simplecpp::TokenList(sp,filenames,"");
3155+
}
3156+
{
3157+
const unsigned char input[] = "code";
3158+
const std::span<const unsigned char, 5> sp = input;
3159+
simplecpp::TokenList(sp,filenames,"");
3160+
}
3161+
# endif
3162+
#endif
3163+
}
3164+
31283165
static void fuzz_crash()
31293166
{
31303167
{
@@ -3390,6 +3427,8 @@ int main(int argc, char **argv)
33903427

33913428
TEST_CASE(preprocess_files);
33923429

3430+
TEST_CASE(safe_api);
3431+
33933432
TEST_CASE(fuzz_crash);
33943433

33953434
return numberOfFailedAssertions > 0 ? EXIT_FAILURE : EXIT_SUCCESS;

0 commit comments

Comments
 (0)