Skip to content

Commit

Permalink
Revert "[ADT] function_ref's constructor is unavailable if the argume…
Browse files Browse the repository at this point in the history
…nt is not callable."

This reverts commit 4cae622.

Breaks GCC build:
http://lab.llvm.org:8011/#/builders/8/builds/33/steps/6/logs/stdio
  • Loading branch information
sam-mccall committed Oct 7, 2020
1 parent fbce456 commit 281703e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 26 deletions.
13 changes: 1 addition & 12 deletions llvm/include/llvm/ADT/STLExtras.h
Expand Up @@ -186,27 +186,16 @@ class function_ref<Ret(Params...)> {
std::forward<Params>(params)...);
}

template <typename Callable,
typename Result =
typename std::result_of<Callable(Params...)>::type>
static constexpr bool IsCompatible =
std::is_void<Ret>::value || std::is_convertible<Result, Ret>::value;

public:
function_ref() = default;
function_ref(std::nullptr_t) {}

template <typename Callable>
// Only allow this constructor if the object is actually callable
// and returns the correct type.
function_ref(
Callable &&callable,
std::enable_if_t<
// This is not the copy-constructor.
!std::is_same<std::remove_cv_t<std::remove_reference_t<Callable>>,
function_ref>::value &&
// Must be callable and return a suitable type.
IsCompatible<Callable>> * = nullptr)
function_ref>::value> * = nullptr)
: callback(callback_fn<typename std::remove_reference<Callable>::type>),
callable(reinterpret_cast<intptr_t>(&callable)) {}

Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/AsmParser/LLParser.h
Expand Up @@ -166,8 +166,8 @@ namespace llvm {
: Context(Context), Lex(F, SM, Err, Context), M(M), Index(Index),
Slots(Slots), BlockAddressPFS(nullptr) {}
bool Run(
bool UpgradeDebugInfo, DataLayoutCallbackTy DataLayoutCallback =
[](StringRef) { return None; });
bool UpgradeDebugInfo,
DataLayoutCallbackTy DataLayoutCallback = [](Module *) {});

bool parseStandaloneConstantValue(Constant *&C, const SlotMapping *Slots);

Expand Down
4 changes: 3 additions & 1 deletion llvm/lib/Bitcode/Reader/BitcodeReader.cpp
Expand Up @@ -579,7 +579,9 @@ class BitcodeReader : public BitcodeReaderBase, public GVMaterializer {
/// \returns true if an error occurred.
Error parseBitcodeInto(
Module *M, bool ShouldLazyLoadMetadata = false, bool IsImporting = false,
DataLayoutCallbackTy DataLayoutCallback = [](StringRef) { return None; });
DataLayoutCallbackTy DataLayoutCallback = [](std::string) {
return None;
});

static uint64_t decodeSignRotatedValue(uint64_t V);

Expand Down
11 changes: 0 additions & 11 deletions llvm/unittests/ADT/FunctionRefTest.cpp
Expand Up @@ -48,15 +48,4 @@ TEST(FunctionRefTest, BadCopy) {
ASSERT_EQ(1, X());
}

// Test that overloads on function_refs are resolved as expected.
const char *returns(StringRef) { return "not a function"; }
const char *returns(function_ref<double()> F) { return "number"; }
const char *returns(function_ref<StringRef()> F) { return "string"; }

TEST(FunctionRefTest, SFINAE) {
EXPECT_EQ("not a function", returns("boo!"));
EXPECT_EQ("number", returns([] { return 42; }));
EXPECT_EQ("string", returns([] { return "hello"; }));
}

} // namespace

0 comments on commit 281703e

Please sign in to comment.