[llvm] r209957 - Turn errc and windows_error into enum classes.
Rafael Espindola
rafael.espindola at gmail.com
Fri May 30 19:29:28 PDT 2014
Author: rafael
Date: Fri May 30 21:29:28 2014
New Revision: 209957
URL: http://llvm.org/viewvc/llvm-project?rev=209957&view=rev
Log:
Turn errc and windows_error into enum classes.
Modified:
llvm/trunk/include/llvm/Support/system_error.h
llvm/trunk/lib/Support/Unix/Path.inc
llvm/trunk/lib/Support/Windows/Path.inc
llvm/trunk/tools/llvm-ar/llvm-ar.cpp
Modified: llvm/trunk/include/llvm/Support/system_error.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/system_error.h?rev=209957&r1=209956&r2=209957&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/system_error.h (original)
+++ llvm/trunk/include/llvm/Support/system_error.h Fri May 30 21:29:28 2014
@@ -482,9 +482,7 @@ template <class Tp> struct is_error_cond
// Some error codes are not present on all platforms, so we provide equivalents
// for them:
-//enum class errc
-struct errc {
-enum _ {
+enum class errc {
success = 0,
address_family_not_supported = EAFNOSUPPORT,
address_in_use = EADDRINUSE,
@@ -606,16 +604,9 @@ enum _ {
wrong_protocol_type = EPROTOTYPE
};
- _ v_;
-
- errc(_ v) : v_(v) {}
- operator int() const {return v_;}
-};
template <> struct is_error_condition_enum<errc> : std::true_type { };
-template <> struct is_error_condition_enum<errc::_> : std::true_type { };
-
class error_condition;
class error_code;
@@ -818,8 +809,7 @@ inline bool operator!=(const error_condi
// To construct an error_code after an API error:
//
// error_code( ::GetLastError(), system_category() )
-struct windows_error {
-enum _ {
+enum class windows_error {
success = 0,
// These names and values are based on Windows WinError.h
// This is not a complete list. Add to this list if you need to explicitly
@@ -876,18 +866,9 @@ enum _ {
cancel_violation = 173, // ERROR_CANCEL_VIOLATION,
already_exists = 183 // ERROR_ALREADY_EXISTS
};
- _ v_;
-
- windows_error(_ v) : v_(v) {}
- explicit windows_error(int v) : v_(_(v)) {}
- operator int() const {return v_;}
-};
-
template <> struct is_error_code_enum<windows_error> : std::true_type { };
-template <> struct is_error_code_enum<windows_error::_> : std::true_type { };
-
inline error_code make_error_code(windows_error e) {
return error_code(static_cast<int>(e), system_category());
}
Modified: llvm/trunk/lib/Support/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=209957&r1=209956&r2=209957&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc (original)
+++ llvm/trunk/lib/Support/Unix/Path.inc Fri May 30 21:29:28 2014
@@ -248,7 +248,7 @@ error_code current_path(SmallVectorImpl<
while (true) {
if (::getcwd(result.data(), result.capacity()) == nullptr) {
// See if there was a real error.
- if (errno != errc::not_enough_memory)
+ if (errno != ENOMEM)
return error_code(errno, system_category());
// Otherwise there just wasn't enough space.
result.reserve(result.capacity() * 2);
@@ -265,7 +265,7 @@ error_code create_directory(const Twine
StringRef p = path.toNullTerminatedStringRef(path_storage);
if (::mkdir(p.begin(), S_IRWXU | S_IRWXG) == -1) {
- if (errno != errc::file_exists || !IgnoreExisting)
+ if (errno != EEXIST || !IgnoreExisting)
return error_code(errno, system_category());
}
@@ -306,7 +306,7 @@ error_code remove(const Twine &path, boo
struct stat buf;
if (lstat(p.begin(), &buf) != 0) {
- if (errno != errc::no_such_file_or_directory || !IgnoreNonExisting)
+ if (errno != ENOENT || !IgnoreNonExisting)
return error_code(errno, system_category());
return error_code();
}
@@ -320,7 +320,7 @@ error_code remove(const Twine &path, boo
return make_error_code(errc::operation_not_permitted);
if (::remove(p.begin()) == -1) {
- if (errno != errc::no_such_file_or_directory || !IgnoreNonExisting)
+ if (errno != ENOENT || !IgnoreNonExisting)
return error_code(errno, system_category());
}
@@ -355,7 +355,7 @@ error_code exists(const Twine &path, boo
StringRef p = path.toNullTerminatedStringRef(path_storage);
if (::access(p.begin(), F_OK) == -1) {
- if (errno != errc::no_such_file_or_directory)
+ if (errno != ENOENT)
return error_code(errno, system_category());
result = false;
} else
Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=209957&r1=209956&r2=209957&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Fri May 30 21:29:28 2014
@@ -810,7 +810,7 @@ error_code openFileForRead(const Twine &
if (EC != windows_error::access_denied)
return EC;
if (is_directory(Name))
- return error_code(errc::is_a_directory, posix_category());
+ return make_error_code(errc::is_a_directory);
return EC;
}
@@ -861,7 +861,7 @@ error_code openFileForWrite(const Twine
if (EC != windows_error::access_denied)
return EC;
if (is_directory(Name))
- return error_code(errc::is_a_directory, posix_category());
+ return make_error_code(errc::is_a_directory);
return EC;
}
Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=209957&r1=209956&r2=209957&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Fri May 30 21:29:28 2014
@@ -453,8 +453,7 @@ int NewArchiveIterator::getFD() const {
// Linux cannot open directories with open(2), although
// cygwin and *bsd can.
if (NewStatus.type() == sys::fs::file_type::directory_file)
- failIfError(error_code(errc::is_a_directory, posix_category()),
- NewFilename);
+ failIfError(make_error_code(errc::is_a_directory), NewFilename);
return NewFD;
}
More information about the llvm-commits
mailing list