From ad7751f430c06834130d38c87476276dbd5cfbbf Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Mon, 4 Mar 2019 01:02:15 -0500 Subject: [PATCH] Remove optional template with cpp_entity Sam was having issues getting this to compile. I had similar issues once I tried to compile in CentOS 7. The errors are related to cpp_entity being a virtual base class that can't be inside a template. --- src/asgn2/buildlist.hpp | 12 +++++++----- src/asgn2/tests.cpp | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/asgn2/buildlist.hpp b/src/asgn2/buildlist.hpp index e03b40d..5751415 100644 --- a/src/asgn2/buildlist.hpp +++ b/src/asgn2/buildlist.hpp @@ -2,26 +2,28 @@ #define __CSE3150_TESTING_BUILDLIST_H #include +#include #include #include #include #include #include -#include -tl::optional find_build_list_fn(const cppast::cpp_file& file) { - tl::optional result = tl::nullopt; +// It'd be better to return an optional cpp_entity, but this breaks on some +// compilers. +const cppast::cpp_entity* find_build_list_fn(const cppast::cpp_file& file) { + const cppast::cpp_entity* result = nullptr; cppast::visit(file, [&](const cppast::cpp_entity& e, cppast::visitor_info info) { const auto is_function = e.kind() == cppast::cpp_entity_kind::function_t; const auto correct_name = e.name() == "buildList"; if (is_function && correct_name) { - result = e; + result = &e; } // Stop visiting further nodes if we found the one we're looking for. - const auto should_keep_looking = result == tl::nullopt; + const auto should_keep_looking = result == nullptr; return should_keep_looking; }); diff --git a/src/asgn2/tests.cpp b/src/asgn2/tests.cpp index f0724d3..7864a41 100644 --- a/src/asgn2/tests.cpp +++ b/src/asgn2/tests.cpp @@ -46,13 +46,13 @@ TEST_CASE("Assignment 2") { } const auto build_list = find_build_list_fn(*w_list_file); - if (!build_list.has_value()) { + if (build_list == nullptr) { FAIL("Make sure the \"buildList\" function exists in \"asgn2/q1/WList.cpp\""); } // Ew... casting. (The first-party example uses it too, so this may be // required by the cppast API design.) - auto& build_list_fn = static_cast(*build_list); + auto& build_list_fn = *static_cast(build_list); if (question.id == "q1" || question.id == "q3") { INFO("\"buildList\" needs to take an \"std::list\" as a reference for q1.\"");