X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2FFormatArg.h;h=a6d4fb63865eb3b7cd0cf0faec1641274f0b10f8;hp=6f25299e5217c647825452a1661386f08aa0e8ab;hb=153c4233eff35be3bd9728c969bd22f59ac6051b;hpb=dee8a5180aa542d98d1b71c74f83a006e4627952 diff --git a/folly/FormatArg.h b/folly/FormatArg.h index 6f25299e..a6d4fb63 100644 --- a/folly/FormatArg.h +++ b/folly/FormatArg.h @@ -1,5 +1,5 @@ /* - * Copyright 2016 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,6 +17,7 @@ #pragma once #include + #include #include #include @@ -25,11 +26,12 @@ namespace folly { class BadFormatArg : public std::invalid_argument { - public: - explicit BadFormatArg(const std::string& msg) - : std::invalid_argument(msg) {} + using invalid_argument::invalid_argument; }; +[[noreturn]] void throwBadFormatArg(char const* msg); +[[noreturn]] void throwBadFormatArg(std::string const& msg); + /** * Parsed format argument. */ @@ -211,8 +213,8 @@ inline std::string FormatArg::errorStr(Args&&... args) const { } template -inline void FormatArg::error(Args&&... args) const { - throw BadFormatArg(errorStr(std::forward(args)...)); +[[noreturn]] inline void FormatArg::error(Args&&... args) const { + throwBadFormatArg(errorStr(std::forward(args)...)); } template @@ -243,10 +245,10 @@ inline StringPiece FormatArg::doSplitKey() { const char* p; if (e[-1] == ']') { --e; - p = static_cast(memchr(b, '[', e - b)); - enforce(p, "unmatched ']'"); + p = static_cast(memchr(b, '[', size_t(e - b))); + enforce(p != nullptr, "unmatched ']'"); } else { - p = static_cast(memchr(b, '.', e - b)); + p = static_cast(memchr(b, '.', size_t(e - b))); } if (p) { key_.assign(p + 1, e); @@ -267,10 +269,10 @@ inline int FormatArg::splitIntKey() { } try { return to(doSplitKey()); - } catch (const std::out_of_range& e) { + } catch (const std::out_of_range&) { error("integer key required"); return 0; // unreached } } -} // namespace folly +} // namespace folly