[PATCH] Support/Unix: use lambda function to fix building errors with clang

Mauro Rossi via llvm-commits llvm-commits at lists.llvm.org
Sun Jul 8 13:28:46 PDT 2018


From: Chih-Wei Huang <cwhuang at linux.org.tw>

The ::open() function has unlimited arguments. Seems the compiler can't
infer the template argument from it:

external/llvm70/lib/Support/Unix/Path.inc:770:19: error: no matching function for call to 'RetryAfterSignal'
  if ((ResultFD = sys::RetryAfterSignal(-1, ::open, P.begin(), OpenFlags, Mode)) <
                  ^~~~~~~~~~~~~~~~~~~~~
external/llvm70/lib/Support/../../include/llvm/Support/Errno.h:34:13: note: candidate template ignored: couldn't infer template argument 'Fun'
inline auto RetryAfterSignal(const FailT &Fail, const Fun &F,
            ^
1 error generated.

To avoid that, use a lambda function to wrap the ::open() function.
---
 lib/Support/Unix/Path.inc    | 4 ++--
 lib/Support/Unix/Process.inc | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc
index b8fea5bda4f..44a8b981c48 100644
--- a/lib/Support/Unix/Path.inc
+++ b/lib/Support/Unix/Path.inc
@@ -766,8 +766,8 @@ std::error_code openFile(const Twine &Name, int &ResultFD,
 
   SmallString<128> Storage;
   StringRef P = Name.toNullTerminatedStringRef(Storage);
-  if ((ResultFD = sys::RetryAfterSignal(-1, ::open, P.begin(), OpenFlags, Mode)) <
-      0)
+  auto openfun([&] { return ::open(P.begin(), OpenFlags, Mode); });
+  if ((ResultFD = sys::RetryAfterSignal(-1, openfun)) < 0)
     return std::error_code(errno, std::generic_category());
 #ifndef O_CLOEXEC
   if (!(Flags & OF_ChildInherit)) {
diff --git a/lib/Support/Unix/Process.inc b/lib/Support/Unix/Process.inc
index fa515d44f3f..1111cd2fe2c 100644
--- a/lib/Support/Unix/Process.inc
+++ b/lib/Support/Unix/Process.inc
@@ -211,7 +211,7 @@ std::error_code Process::FixupStandardFileDescriptors() {
     assert(errno == EBADF && "expected errno to have EBADF at this point!");
 
     if (NullFD < 0) {
-      if ((NullFD = RetryAfterSignal(-1, ::open, "/dev/null", O_RDWR)) < 0)
+      if ((NullFD = RetryAfterSignal(-1, [] { return ::open("/dev/null", O_RDWR); })) < 0)
         return std::error_code(errno, std::generic_category());
     }
 
-- 
2.17.1



More information about the llvm-commits mailing list