Skip to content

Variant submodule #4344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR
endif()
endif()

add_subdirectory(lib/variant)

add_subdirectory(src)
add_subdirectory(regression)
add_subdirectory(unit)
Expand Down
2 changes: 1 addition & 1 deletion src/util/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,4 @@ add_dependencies(util generate_version_cpp)

generic_includes(util)

target_link_libraries(util big-int langapi)
target_link_libraries(util big-int langapi mpark_variant)
2 changes: 2 additions & 0 deletions src/util/module_dependencies.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
big-int
mach # system
malloc # system
mpark
nonstd
sys # system
util

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed

18 changes: 18 additions & 0 deletions src/util/variant.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*******************************************************************\

Module: typedef for variant class template. To be replaced with
std::variant once C++17 support is enabled

Author: Diffblue Ltd.

\*******************************************************************/

#ifndef CPROVER_UTIL_VARIANT_H
#define CPROVER_UTIL_VARIANT_H

#include <mpark/variant.hpp>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose this works with CMake, but shouldn't this be #include <lib/variant/mpark/variant.hpp>? If that, however, does not work with CMake then we'd need to update INCLUDES in any Makefile that wants to use this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So only the util includes need to change, since all other users should use the variantt wrapper. But happy to do that if that's the preference.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, but the variant.h file uses this include, so if I'm in directory X and have a file x/y.cpp that includes variant.h then the preprocessor still needs to know how to resolve that include.


template <typename... Ts>
using variantt = mpark::variant<Ts...>;

#endif // CPROVER_UTIL_VARIANT_H
1 change: 1 addition & 0 deletions unit/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ SRC += analyses/ai/ai.cpp \
util/symbol_table.cpp \
util/symbol.cpp \
util/unicode.cpp \
util/variant.cpp \
# Empty last line

INCLUDES= -I ../src/ -I.
Expand Down
12 changes: 12 additions & 0 deletions unit/util/variant.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2016-2019 Diffblue Limited. All Rights Reserved.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong copyright header


#include <testing-utils/use_catch.h>
#include <util/variant.h>

TEST_CASE("Ensure variant has been included", "[core][util][variant]")
{
variantt<int, float> some_type = 1;
REQUIRE(some_type.index() == 0);
some_type = 1.0f;
REQUIRE(some_type.index() == 1);
}