File tree Expand file tree Collapse file tree 2 files changed +6
-1
lines changed
Expand file tree Collapse file tree 2 files changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -506,7 +506,9 @@ class FormatArg
506506
507507 template <typename T>
508508 FormatArg (const T& value)
509- : m_value(static_cast <const void *>(&value)),
509+ // C-style cast here allows us to also remove volatile; we put it
510+ // back in the *Impl functions before dereferencing to avoid UB.
511+ : m_value((const void *)(&value)),
510512 m_formatImpl(&formatImpl<T>),
511513 m_toIntImpl(&toIntImpl<T>)
512514 { }
Original file line number Diff line number Diff line change @@ -286,6 +286,9 @@ int unitTests()
286286
287287 // ------------------------------------------------------------
288288 // Misc
289+ volatile int i = 1234 ;
290+ CHECK_EQUAL (tfm::format (" %d" , i), " 1234" );
291+
289292#ifdef TEST_WCHAR_T_COMPILE
290293 // Test wchar_t handling - should fail to compile!
291294 tfm::format (" %ls" , L" blah" );
You can’t perform that action at this time.
0 commit comments