Unary minus operator applied to unsigned type, result still unsigned.
Use ~0U instead of -1U and 1 + ~VAL instead of -VAL.
Paths
| Differential D94417
[ADT][Support] Fix C4146 error from MSVC ClosedPublic Authored by vinograd47 on Jan 11 2021, 7:24 AM.
Details Summary Unary minus operator applied to unsigned type, result still unsigned. Use ~0U instead of -1U and 1 + ~VAL instead of -VAL.
Diff Detail
Event TimelineComment Actions Perhaps we could rewrite the code to use ~ or the like instead of unary - if that works? Comment Actions
+1 We currently globally disable C4146 inside llvm-project\llvm\cmake\modules\HandleLLVMOptions.cmake (along with a lot of other warnings that ideally we'd enable and make use of) - it'd be great if you could fix at least the code here instead of adding a lot of pragmas. vinograd47 retitled this revision from [ADT][Support] Disable C4146 MSVC warning to [ADT][Support] Fix C4146 error from MSVC. Comment ActionsReworked the patch. Fixed the warning instead of disabling it. Comment Actions Seems OK - I don't know if there's a nicer way to handle the latter cases that need the 1 + ~N. This revision is now accepted and ready to land.Jan 12 2021, 11:26 AM Comment Actions Can you commit this yourself (do you have commit access), or do you need someone to commit it for you? Comment Actions @dblaikie I'm not sure if I have commit access. But after rebase CI shows unit tests failures, I need to investigate them prior to merging. Comment Actions @dblaikie I see similar failures locally even on clean main branch without this changes. Is it some known issue? Closed by commit rG76f5c5a7b059: [ADT][Support] Fix C4146 error from MSVC (authored by vinograd47, committed by dblaikie). · Explain WhyJan 15 2021, 2:34 PM This revision was automatically updated to reflect the committed changes.
Revision Contents
Diff 316885 llvm/include/llvm/ADT/StringExtras.h
llvm/include/llvm/Support/MathExtras.h
|
clang-format not found in user's PATH; not linting file.