[PATCH] D115031: [AST] Print NTTP args as string-literals when possible

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 28 12:42:08 PST 2022


aaron.ballman added inline comments.


================
Comment at: clang/include/clang/Basic/CharInfo.h:199-200
+    return "\\t";
+  case '\v':
+    return "\\v";
+  }
----------------
lichray wrote:
> aaron.ballman wrote:
> > We're also missing `\?` right?
> `?` does not seem to need `"escaping?"`
It's the only simple escape sequence we're not handling here: http://eel.is/c++draft/lex.literal#nt:simple-escape-sequence-char

(You need to escape `?` thanks to trigraphs. Consider a string literal like `"This does what now??!"`.)


================
Comment at: clang/lib/AST/APValue.cpp:676-683
+  if (Ty->isWideCharType())
+    Out << 'L';
+  else if (Ty->isChar8Type())
+    Out << "u8";
+  else if (Ty->isChar16Type())
+    Out << 'u';
+  else if (Ty->isChar32Type())
----------------
lichray wrote:
> aaron.ballman wrote:
> > Not quite the same thing, but do we have to worry about printing pascal strings here? (e.g., do we need to do `"\pwhatever"`?
> This is in `APValue` where we lost the context of StringLiteral; nothing tells me that this array was created from a Pascal string literal. Unless you want to do some heuristics, like printing `"\pthis"` when seens an `unsigned char[6]` where the first element = 4 (last element = 0 is checked at the beginning).
Whelp, that explains that. I think the current behavior is fine (I have to imagine the number of people still using Pascal strings is as high as four or five these days).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115031



More information about the cfe-commits mailing list