Unify default construction of error_code uses on this idiom so that users don't
feel compelled to make static globals for naming convenience. (unfortunately I
couldn't make the original ctor private as some APIs don't return their result,
instead using an out parameter (that makes sense to default construct) - which
is a bit of a pity. I did, however, find/fix some cases of unnecessary default
construction of error_code before I hit the unfixable cases)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150197
91177308-0d34-0410-b5e6-
96231b3b80d8
public:
error_code() : _val_(0), _cat_(&system_category()) {}
public:
error_code() : _val_(0), _cat_(&system_category()) {}
+ static error_code success() {
+ return error_code();
+ }
+
error_code(int _val, const error_category& _cat)
: _val_(_val), _cat_(&_cat) {}
error_code(int _val, const error_category& _cat)
: _val_(_val), _cat_(&_cat) {}
if (Filename == "-") {
Fd = 0;
sys::Program::ChangeStdinToBinary();
if (Filename == "-") {
Fd = 0;
sys::Program::ChangeStdinToBinary();
+ return error_code::success();
}
int OpenFlags = O_RDONLY;
}
int OpenFlags = O_RDONLY;
Fd = ::open(Filename.c_str(), OpenFlags);
if (Fd == -1)
return error_code(errno, posix_category());
Fd = ::open(Filename.c_str(), OpenFlags);
if (Fd == -1)
return error_code(errno, posix_category());
+ return error_code::success();
// Now its safe to mmap the files into memory because both files
// have a non-zero size.
// Now its safe to mmap the files into memory because both files
// have a non-zero size.
OwningPtr<MemoryBuffer> F1;
if (error_code ec = MemoryBuffer::getFile(FileA.c_str(), F1)) {
if (Error)
OwningPtr<MemoryBuffer> F1;
if (error_code ec = MemoryBuffer::getFile(FileA.c_str(), F1)) {
if (Error)
#include <fcntl.h>
using namespace llvm;
#include <fcntl.h>
using namespace llvm;
-namespace { const llvm::error_code success; }
-
//===----------------------------------------------------------------------===//
// MemoryBuffer implementation itself.
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// MemoryBuffer implementation itself.
//===----------------------------------------------------------------------===//
RealMapOffset)) {
result.reset(GetNamedBuffer<MemoryBufferMMapFile>(
StringRef(Pages + Delta, MapSize), Filename, RequiresNullTerminator));
RealMapOffset)) {
result.reset(GetNamedBuffer<MemoryBufferMMapFile>(
StringRef(Pages + Delta, MapSize), Filename, RequiresNullTerminator));
+ return error_code::success();
+ return error_code::success();
}
//===----------------------------------------------------------------------===//
}
//===----------------------------------------------------------------------===//
} while (ReadBytes != 0);
result.reset(getMemBufferCopy(Buffer, "<stdin>"));
} while (ReadBytes != 0);
result.reset(getMemBufferCopy(Buffer, "<stdin>"));
+ return error_code::success();
const char prefered_separator = '/';
#endif
const char prefered_separator = '/';
#endif
- const llvm::error_code success;
-
StringRef find_first_component(StringRef path) {
// Look for this first component in the following order.
// * empty (in this case we return an empty string)
StringRef find_first_component(StringRef path) {
// Look for this first component in the following order.
// * empty (in this case we return an empty string)
// Already absolute.
if (rootName && rootDirectory)
// Already absolute.
if (rootName && rootDirectory)
+ return error_code::success();
// All of the following conditions will need the current directory.
SmallString<128> current_dir;
// All of the following conditions will need the current directory.
SmallString<128> current_dir;
path::append(current_dir, p);
// Set path to the result.
path.swap(current_dir);
path::append(current_dir, p);
// Set path to the result.
path.swap(current_dir);
+ return error_code::success();
}
if (!rootName && rootDirectory) {
}
if (!rootName && rootDirectory) {
path::append(curDirRootName, p);
// Set path to the result.
path.swap(curDirRootName);
path::append(curDirRootName, p);
// Set path to the result.
path.swap(curDirRootName);
+ return error_code::success();
}
if (rootName && !rootDirectory) {
}
if (rootName && !rootDirectory) {
SmallString<128> res;
path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
path.swap(res);
SmallString<128> res;
path::append(res, pRootName, bRootDirectory, bRelativePath, pRelativePath);
path.swap(res);
+ return error_code::success();
}
llvm_unreachable("All rootName and rootDirectory combinations should have "
}
llvm_unreachable("All rootName and rootDirectory combinations should have "
if (error_code ec = status(path, st))
return ec;
result = is_directory(st);
if (error_code ec = status(path, st))
return ec;
result = is_directory(st);
+ return error_code::success();
}
bool is_regular_file(file_status status) {
}
bool is_regular_file(file_status status) {
if (error_code ec = status(path, st))
return ec;
result = is_regular_file(st);
if (error_code ec = status(path, st))
return ec;
result = is_regular_file(st);
+ return error_code::success();
}
bool is_symlink(file_status status) {
}
bool is_symlink(file_status status) {
if (error_code ec = status(path, st))
return ec;
result = is_symlink(st);
if (error_code ec = status(path, st))
return ec;
result = is_symlink(st);
+ return error_code::success();
}
bool is_other(file_status status) {
}
bool is_other(file_status status) {
if (ec == errc::value_too_large) {
// Magic.size() > file_size(Path).
result = false;
if (ec == errc::value_too_large) {
// Magic.size() > file_size(Path).
result = false;
+ return error_code::success();
}
return ec;
}
result = Magic == Buffer;
}
return ec;
}
result = Magic == Buffer;
+ return error_code::success();
}
/// @brief Identify the magic in magic.
}
/// @brief Identify the magic in magic.
return ec;
result = identify_magic(Magic);
return ec;
result = identify_magic(Magic);
+ return error_code::success();
+ return error_code::success();
}
} // end unnamed namespace
}
} // end unnamed namespace
result.clear();
StringRef d(dir);
result.append(d.begin(), d.end());
result.clear();
StringRef d(dir);
result.append(d.begin(), d.end());
+ return error_code::success();
}
result.set_size(strlen(result.data()));
}
result.set_size(strlen(result.data()));
+ return error_code::success();
}
error_code copy_file(const Twine &from, const Twine &to, copy_option copt) {
}
error_code copy_file(const Twine &from, const Twine &to, copy_option copt) {
if (sz_read < 0)
return error_code(errno, system_category());
if (sz_read < 0)
return error_code(errno, system_category());
+ return error_code::success();
}
error_code create_directory(const Twine &path, bool &existed) {
}
error_code create_directory(const Twine &path, bool &existed) {
+ return error_code::success();
}
error_code create_hard_link(const Twine &to, const Twine &from) {
}
error_code create_hard_link(const Twine &to, const Twine &from) {
if (::link(t.begin(), f.begin()) == -1)
return error_code(errno, system_category());
if (::link(t.begin(), f.begin()) == -1)
return error_code(errno, system_category());
+ return error_code::success();
}
error_code create_symlink(const Twine &to, const Twine &from) {
}
error_code create_symlink(const Twine &to, const Twine &from) {
if (::symlink(t.begin(), f.begin()) == -1)
return error_code(errno, system_category());
if (::symlink(t.begin(), f.begin()) == -1)
return error_code(errno, system_category());
+ return error_code::success();
}
error_code remove(const Twine &path, bool &existed) {
}
error_code remove(const Twine &path, bool &existed) {
+ return error_code::success();
}
error_code rename(const Twine &from, const Twine &to) {
}
error_code rename(const Twine &from, const Twine &to) {
return error_code(errno, system_category());
}
return error_code(errno, system_category());
}
+ return error_code::success();
}
error_code resize_file(const Twine &path, uint64_t size) {
}
error_code resize_file(const Twine &path, uint64_t size) {
if (::truncate(p.begin(), size) == -1)
return error_code(errno, system_category());
if (::truncate(p.begin(), size) == -1)
return error_code(errno, system_category());
+ return error_code::success();
}
error_code exists(const Twine &path, bool &result) {
}
error_code exists(const Twine &path, bool &result) {
+ return error_code::success();
}
bool equivalent(file_status A, file_status B) {
}
bool equivalent(file_status A, file_status B) {
if (error_code ec = status(A, fsA)) return ec;
if (error_code ec = status(B, fsB)) return ec;
result = equivalent(fsA, fsB);
if (error_code ec = status(A, fsA)) return ec;
if (error_code ec = status(B, fsB)) return ec;
result = equivalent(fsA, fsB);
+ return error_code::success();
}
error_code file_size(const Twine &path, uint64_t &result) {
}
error_code file_size(const Twine &path, uint64_t &result) {
return make_error_code(errc::operation_not_permitted);
result = status.st_size;
return make_error_code(errc::operation_not_permitted);
result = status.st_size;
+ return error_code::success();
}
error_code status(const Twine &path, file_status &result) {
}
error_code status(const Twine &path, file_status &result) {
result.st_dev = status.st_dev;
result.st_ino = status.st_ino;
result.st_dev = status.st_dev;
result.st_ino = status.st_ino;
+ return error_code::success();
}
error_code unique_file(const Twine &model, int &result_fd,
}
error_code unique_file(const Twine &model, int &result_fd,
result_path.append(d.begin(), d.end());
result_fd = RandomFD;
result_path.append(d.begin(), d.end());
result_fd = RandomFD;
+ return error_code::success();
}
error_code detail::directory_iterator_construct(detail::DirIterState &it,
}
error_code detail::directory_iterator_construct(detail::DirIterState &it,
::closedir(reinterpret_cast<DIR *>(it.IterationHandle));
it.IterationHandle = 0;
it.CurrentEntry = directory_entry();
::closedir(reinterpret_cast<DIR *>(it.IterationHandle));
it.IterationHandle = 0;
it.CurrentEntry = directory_entry();
+ return error_code::success();
}
error_code detail::directory_iterator_increment(detail::DirIterState &it) {
}
error_code detail::directory_iterator_increment(detail::DirIterState &it) {
} else
return directory_iterator_destruct(it);
} else
return directory_iterator_destruct(it);
+ return error_code::success();
}
error_code get_magic(const Twine &path, uint32_t len,
}
error_code get_magic(const Twine &path, uint32_t len,
}
std::fclose(file);
result.set_size(len);
}
std::fclose(file);
result.set_size(len);
+ return error_code::success();
utf16.push_back(0);
utf16.pop_back();
utf16.push_back(0);
utf16.pop_back();
+ return error_code::success();
}
error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len,
}
error_code UTF16ToUTF8(const wchar_t *utf16, size_t utf16_len,
utf8.push_back(0);
utf8.pop_back();
utf8.push_back(0);
utf8.pop_back();
+ return error_code::success();
}
error_code TempDir(SmallVectorImpl<wchar_t> &result) {
}
error_code TempDir(SmallVectorImpl<wchar_t> &result) {
+ return error_code::success();
}
bool is_separator(const wchar_t value) {
}
bool is_separator(const wchar_t value) {
if (len == 0)
return windows_error(::GetLastError());
if (len == 0)
return windows_error(::GetLastError());
+ return error_code::success();
}
error_code copy_file(const Twine &from, const Twine &to, copy_option copt) {
}
error_code copy_file(const Twine &from, const Twine &to, copy_option copt) {
if (res == 0)
return windows_error(::GetLastError());
if (res == 0)
return windows_error(::GetLastError());
+ return error_code::success();
}
error_code create_directory(const Twine &path, bool &existed) {
}
error_code create_directory(const Twine &path, bool &existed) {
+ return error_code::success();
}
error_code create_hard_link(const Twine &to, const Twine &from) {
}
error_code create_hard_link(const Twine &to, const Twine &from) {
if (!::CreateHardLinkW(wide_from.begin(), wide_to.begin(), NULL))
return windows_error(::GetLastError());
if (!::CreateHardLinkW(wide_from.begin(), wide_to.begin(), NULL))
return windows_error(::GetLastError());
+ return error_code::success();
}
error_code create_symlink(const Twine &to, const Twine &from) {
}
error_code create_symlink(const Twine &to, const Twine &from) {
if (!create_symbolic_link_api(wide_from.begin(), wide_to.begin(), 0))
return windows_error(::GetLastError());
if (!create_symbolic_link_api(wide_from.begin(), wide_to.begin(), 0))
return windows_error(::GetLastError());
+ return error_code::success();
}
error_code remove(const Twine &path, bool &existed) {
}
error_code remove(const Twine &path, bool &existed) {
+ return error_code::success();
}
error_code rename(const Twine &from, const Twine &to) {
}
error_code rename(const Twine &from, const Twine &to) {
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING))
return windows_error(::GetLastError());
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING))
return windows_error(::GetLastError());
+ return error_code::success();
}
error_code resize_file(const Twine &path, uint64_t size) {
}
error_code resize_file(const Twine &path, uint64_t size) {
result = false;
} else
result = true;
result = false;
} else
result = true;
+ return error_code::success();
}
bool equivalent(file_status A, file_status B) {
}
bool equivalent(file_status A, file_status B) {
if (error_code ec = status(A, fsA)) return ec;
if (error_code ec = status(B, fsB)) return ec;
result = equivalent(fsA, fsB);
if (error_code ec = status(A, fsA)) return ec;
if (error_code ec = status(B, fsB)) return ec;
result = equivalent(fsA, fsB);
+ return error_code::success();
}
error_code file_size(const Twine &path, uint64_t &result) {
}
error_code file_size(const Twine &path, uint64_t &result) {
(uint64_t(FileData.nFileSizeHigh) << (sizeof(FileData.nFileSizeLow) * 8))
+ FileData.nFileSizeLow;
(uint64_t(FileData.nFileSizeHigh) << (sizeof(FileData.nFileSizeLow) * 8))
+ FileData.nFileSizeLow;
+ return error_code::success();
}
static bool isReservedName(StringRef path) {
}
static bool isReservedName(StringRef path) {
StringRef path8 = path.toStringRef(path_storage);
if (isReservedName(path8)) {
result = file_status(file_type::character_file);
StringRef path8 = path.toStringRef(path_storage);
if (isReservedName(path8)) {
result = file_status(file_type::character_file);
+ return error_code::success();
}
if (error_code ec = UTF8ToUTF16(path8, path_utf16))
}
if (error_code ec = UTF8ToUTF16(path8, path_utf16))
result.VolumeSerialNumber = Info.dwVolumeSerialNumber;
}
result.VolumeSerialNumber = Info.dwVolumeSerialNumber;
}
+ return error_code::success();
handle_status_error:
error_code ec = windows_error(::GetLastError());
handle_status_error:
error_code ec = windows_error(::GetLastError());
+ return error_code::success();
}
error_code unique_file(const Twine &model, int &result_fd,
}
error_code unique_file(const Twine &model, int &result_fd,
+ return error_code::success();
}
error_code get_magic(const Twine &path, uint32_t len,
}
error_code get_magic(const Twine &path, uint32_t len,
+ return error_code::success();
}
error_code detail::directory_iterator_construct(detail::DirIterState &it,
}
error_code detail::directory_iterator_construct(detail::DirIterState &it,
path::append(directory_entry_path, directory_entry_name_utf8.str());
it.CurrentEntry = directory_entry(directory_entry_path.str());
path::append(directory_entry_path, directory_entry_name_utf8.str());
it.CurrentEntry = directory_entry(directory_entry_path.str());
+ return error_code::success();
}
error_code detail::directory_iterator_destruct(detail::DirIterState &it) {
}
error_code detail::directory_iterator_destruct(detail::DirIterState &it) {
ScopedFindHandle close(HANDLE(it.IterationHandle));
it.IterationHandle = 0;
it.CurrentEntry = directory_entry();
ScopedFindHandle close(HANDLE(it.IterationHandle));
it.IterationHandle = 0;
it.CurrentEntry = directory_entry();
+ return error_code::success();
}
error_code detail::directory_iterator_increment(detail::DirIterState &it) {
}
error_code detail::directory_iterator_increment(detail::DirIterState &it) {
return ec;
it.CurrentEntry.replace_filename(Twine(directory_entry_path_utf8));
return ec;
it.CurrentEntry.replace_filename(Twine(directory_entry_path_utf8));
+ return error_code::success();