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
506
506
507
507
template <typename T>
508
508
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)),
510
512
m_formatImpl(&formatImpl<T>),
511
513
m_toIntImpl(&toIntImpl<T>)
512
514
{ }
Original file line number Diff line number Diff line change @@ -286,6 +286,9 @@ int unitTests()
286
286
287
287
// ------------------------------------------------------------
288
288
// Misc
289
+ volatile int i = 1234 ;
290
+ CHECK_EQUAL (tfm::format (" %d" , i), " 1234" );
291
+
289
292
#ifdef TEST_WCHAR_T_COMPILE
290
293
// Test wchar_t handling - should fail to compile!
291
294
tfm::format (" %ls" , L" blah" );
You can’t perform that action at this time.
0 commit comments