Skip to content
Snippets Groups Projects
Commit 5d9aa31c authored by Pietro Fezzardi's avatar Pietro Fezzardi
Browse files

Remove useless type `GenericFunctor`

`GenericFunctor` is substituted with the `std::integral_constant`
template. This also allows us to remove code that requires C++14.

It also removes the now useless cmake tests on the compiler flag
`-Wno-error=noexcept-type` that was introduced to disable fatal warnings
on the type `GenericFunctor`.
Now that this type has been removed the check is not necessary anymore,
because the `std::integral_constant` template used now does not cause
the warning.
So we can go back to enabling the fatal warnings.
parent 97ed77d2
No related branches found
No related tags found
No related merge requests found
......@@ -77,7 +77,6 @@ endmacro()
add_flag_if_available("-Wno-error=unused-variable")
add_flag_if_available("-Wno-error=unused-function")
add_flag_if_available("-Wno-error=return-type")
add_flag_if_available("-Wno-error=noexcept-type")
add_flag_if_available("-Wno-error=unused-but-set-variable")
add_flag_if_available("-Wno-error=maybe-uninitialized")
add_flag_if_available("-Wno-error=ignored-attributes")
......
......@@ -14,6 +14,7 @@
#include <iostream>
#include <sstream>
#include <string>
#include <type_traits>
#include <vector>
extern "C" {
......@@ -55,7 +56,15 @@ struct ProgramParameters {
bool External;
};
using LibraryDestructor = GenericFunctor<decltype(&dlclose), &dlclose>;
// When LibraryPointer is destroyed, the destructor calls
// LibraryDestructor::operator()(LibraryPointer::get()).
// The problem is that LibraryDestructor::operator() does not take arguments,
// while the destructor tries to pass a void * argument, so it does not match.
// However, LibraryDestructor is an alias for
// std::intgral_constant<decltype(&dlclose), &dlclose >, which has an implicit
// conversion operator to value_type, which unwraps the &dlclose from the
// std::integral_constant, making it callable.
using LibraryDestructor = std::integral_constant<decltype(&dlclose), &dlclose>;
using LibraryPointer = std::unique_ptr<void, LibraryDestructor>;
static const char *const Usage[] = {
......
......@@ -7,6 +7,7 @@
// Standard includes
#include <memory>
#include <type_traits>
// Local includes
#include "revamb.h"
......@@ -14,8 +15,8 @@
#include "ptc.h"
using PTCInstructionListDestructor =
GenericFunctor<decltype(&ptc_instruction_list_free),
&ptc_instruction_list_free>;
std::integral_constant<decltype(&ptc_instruction_list_free),
&ptc_instruction_list_free>;
using PTCInstructionListPtr = std::unique_ptr<PTCInstructionList,
PTCInstructionListDestructor>;
......
......@@ -115,15 +115,6 @@ private:
llvm::StringRef StackPointerRegister;
};
// TODO: this requires C++14
template<typename FnTy, FnTy Ptr>
struct GenericFunctor {
template<typename... Args>
auto operator()(Args... args) -> decltype(Ptr(args...)) {
return Ptr(args...);
}
};
// TODO: move me somewhere more appropriate
static inline bool startsWith(std::string String, std::string Prefix) {
return String.substr(0, Prefix.size()) == Prefix;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment