<div dir="ltr">Couldn't you define a class FormatString like this:<div><br></div><div>class FormatString {</div><div>  template<int N></div><div>  constexpr FormatString(const char (&S)[N]) {</div><div>    tokenize();</div><div>  }</div><div><br></div><div>  FormatString(const char *s) {}</div><div>};</div><div><br></div><div>Then define the format function as format(const FormatString &S, Ts &&...Args)</div><div><br></div><div>The implicit conversion from string literal would go to the constexpr constructor which could tokenize the string at compile time, while implicit conversion from non-literal would be tokenized at runtime.</div><div><br></div><div>If that doesn't work, then like you said, you could use a UDL to force the checking at compile time.</div></div><br><div class="gmail_quote"><div dir="ltr">On Wed, Oct 12, 2016 at 1:01 PM Tim Shen <<a href="mailto:timshen@google.com">timshen@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div dir="ltr" class="gmail_msg">On Wed, Oct 12, 2016 at 12:35 PM Zachary Turner via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="gmail_msg" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br class="gmail_msg"></div><blockquote class="gmail_quote gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">You get compile time checking automatically when we can use c++14 though.  If you use it with a string literal, you'll get compile time checking, otherwise you won't.<br class="gmail_msg"></blockquote><div class="gmail_msg"><br class="gmail_msg"></div></div></div><div dir="ltr" class="gmail_msg"><div class="gmail_quote gmail_msg"><div class="gmail_msg">Even with C++14, os.format("literal format", a, b, c) cannot do the compile-time checking (I maybe wrong with understanding C++14 constexpr). You probably need to add a overloaded version like `os.format(static_format("literal format"), a, b, c)`, or `os.format("literal format"_fmt, a, b, c)` to hold the compile-time checked version.</div><div class="gmail_msg"><br class="gmail_msg"></div><div class="gmail_msg">But anyway, the current interface os.format(const char*, ...) is forward-compatible.</div></div></div>
</blockquote></div>