Skip to content

Commit

Permalink
Allow formatting of volatile variables. (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
c42f authored Dec 13, 2019
1 parent 705e3f4 commit 2f9335a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion tinyformat.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ class FormatArg

template<typename T>
FormatArg(const T& value)
: m_value(static_cast<const void*>(&value)),
// C-style cast here allows us to also remove volatile; we put it
// back in the *Impl functions before dereferencing to avoid UB.
: m_value((const void*)(&value)),
m_formatImpl(&formatImpl<T>),
m_toIntImpl(&toIntImpl<T>)
{ }
Expand Down
3 changes: 3 additions & 0 deletions tinyformat_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ int unitTests()

//------------------------------------------------------------
// Misc
volatile int i = 1234;
CHECK_EQUAL(tfm::format("%d", i), "1234");

#ifdef TEST_WCHAR_T_COMPILE
// Test wchar_t handling - should fail to compile!
tfm::format("%ls", L"blah");
Expand Down

0 comments on commit 2f9335a

Please sign in to comment.