mirror of
https://github.com/microsoft/GSL.git
synced 2024-11-03 17:56:43 -05:00
Add test to demonstrate byte aliasing problem on g++ and clang++
This commit is contained in:
parent
e4a34128a8
commit
1869ff56b3
@ -24,9 +24,9 @@ else()
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++14" COMPILER_SUPPORTS_CXX14)
|
||||
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
|
||||
if(COMPILER_SUPPORTS_CXX14)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -Wall -Wno-missing-braces")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14 -O3 -Wall -Wno-missing-braces")
|
||||
elseif(COMPILER_SUPPORTS_CXX11)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wno-missing-braces")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -O3 -Wall -Wno-missing-braces")
|
||||
else()
|
||||
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
|
||||
endif()
|
||||
|
@ -61,6 +61,20 @@ SUITE(byte_tests)
|
||||
//}
|
||||
}
|
||||
|
||||
int modify_both(gsl::byte * b, int* i)
|
||||
{
|
||||
*i = 10;
|
||||
*b = to_byte<5>();
|
||||
return *i;
|
||||
}
|
||||
|
||||
TEST(aliasing)
|
||||
{
|
||||
int i{0};
|
||||
int res = modify_both(reinterpret_cast<byte*>(&i), &i);
|
||||
CHECK(res == i);
|
||||
}
|
||||
|
||||
TEST(bitwise_operations)
|
||||
{
|
||||
byte b = to_byte<0xFF>();
|
||||
|
Loading…
Reference in New Issue
Block a user