Skip to content

Commit

Permalink
Use [[noreturn]] instead of declspec(noreturn)
Browse files Browse the repository at this point in the history
  • Loading branch information
ras0219-msft authored and alexkaratarakis committed Apr 1, 2017
1 parent 095d329 commit 31e5570
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
18 changes: 12 additions & 6 deletions toolsrc/include/vcpkg_Checks.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@

namespace vcpkg::Checks
{
__declspec(noreturn) void unreachable(const LineInfo& line_info);
[[noreturn]]
void unreachable(const LineInfo& line_info);

_declspec(noreturn) void exit_with_code(const LineInfo& line_info, const int exit_code);
[[noreturn]]
void exit_with_code(const LineInfo& line_info, const int exit_code);

_declspec(noreturn) inline void exit_fail(const LineInfo& line_info)
[[noreturn]]
inline void exit_fail(const LineInfo& line_info)
{
exit_with_code(line_info, EXIT_FAILURE);
}

_declspec(noreturn) inline void exit_success(const LineInfo& line_info)
[[noreturn]]
inline void exit_success(const LineInfo& line_info)
{
exit_with_code(line_info, EXIT_SUCCESS);
}

// Part of the reason these exist is to not include extra headers in this one to avoid circular #includes.
_declspec(noreturn) void exit_with_message(const LineInfo& line_info, const cstring_view errorMessage);
[[noreturn]]
void exit_with_message(const LineInfo& line_info, const cstring_view errorMessage);

template <class Arg1, class...Args>
_declspec(noreturn) void exit_with_message(const LineInfo& line_info, const char* errorMessageTemplate, const Arg1 errorMessageArg1, const Args&... errorMessageArgs)
[[noreturn]]
void exit_with_message(const LineInfo& line_info, const char* errorMessageTemplate, const Arg1 errorMessageArg1, const Args&... errorMessageArgs)
{
exit_with_message(line_info, Strings::format(errorMessageTemplate, errorMessageArg1, errorMessageArgs...));
}
Expand Down
3 changes: 2 additions & 1 deletion toolsrc/include/vcpkg_Enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ namespace vcpkg::Enums
{
std::string nullvalue_toString(const std::string& enum_name);

__declspec(noreturn) void nullvalue_used(const LineInfo& line_info, const std::string& enum_name);
[[noreturn]]
void nullvalue_used(const LineInfo& line_info, const std::string& enum_name);
}
7 changes: 5 additions & 2 deletions toolsrc/src/vcpkg_Checks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

namespace vcpkg::Checks
{
__declspec(noreturn) void unreachable(const LineInfo& line_info)
[[noreturn]]
void unreachable(const LineInfo& line_info)
{
System::println(System::color::error, "Error: Unreachable code was reached");
System::println(System::color::error, line_info.toString()); // Always print line_info here
Expand All @@ -16,6 +17,7 @@ namespace vcpkg::Checks
#endif
}

[[noreturn]]
void exit_with_code(const LineInfo& line_info, const int exit_code)
{
if (g_debugging)
Expand All @@ -26,7 +28,8 @@ namespace vcpkg::Checks
::exit(exit_code);
}

__declspec(noreturn) void exit_with_message(const LineInfo& line_info, const cstring_view errorMessage)
[[noreturn]]
void exit_with_message(const LineInfo& line_info, const cstring_view errorMessage)
{
System::println(System::color::error, errorMessage);
exit_fail(line_info);
Expand Down
3 changes: 2 additions & 1 deletion toolsrc/src/vcpkg_Enums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ namespace vcpkg::Enums
return Strings::format("%s_NULLVALUE", enum_name);
}

__declspec(noreturn) void nullvalue_used(const LineInfo& line_info, const std::string& enum_name)
[[noreturn]]
void nullvalue_used(const LineInfo& line_info, const std::string& enum_name)
{
Checks::exit_with_message(line_info, "NULLVALUE of enum %s was used", enum_name);
}
Expand Down

0 comments on commit 31e5570

Please sign in to comment.