[libcxx-commits] [PATCH] D103444: [libcxx] Don't use an undefined '+' in unsigned/octal/hexal print formats

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Jun 1 06:25:51 PDT 2021


Quuxplusone accepted this revision as: Quuxplusone.
Quuxplusone added a comment.

Looks reasonable to me. FWIW, a more invasive rewrite would put the letter-computing code //first://

      char letter = ((__flags & ios_base::basefield) == ios_base::oct) ? 'o' :
          ((__flags & ios_base::basefield) == ios_base::hex) ? 'x' :
          __signd ? 'd' : 'u';
      if (letter == 'd' && (__flags & ios_base::showpos))
          *__fmtp++ = '+';
      if (__flags & ios_base::showbase)
          *__fmtp++ = '#';
      while (*__len)
          *__fmtp++ = *__len++;
      *__fmtp++ = letter;
  }

(Notice the names don't have to be _Uglified in this file because it's not a header.)



================
Comment at: libcxx/src/locale.cpp:4600
 {
-    if (__flags & ios_base::showpos)
+    if (__flags & ios_base::showpos &&
+        (__flags & ios_base::basefield) != ios_base::oct &&
----------------
Please parenthesize `(__flags & ios_base::showpos)` for clarity. (Otherwise I could imagine a compiler thinking you'd typoed `&` for `&&`.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103444/new/

https://reviews.llvm.org/D103444



More information about the libcxx-commits mailing list