[all-commits] [llvm/llvm-project] 44eee6: [AST] Print NTTP args as string-literals when poss...

zhihaoy via All-commits all-commits at lists.llvm.org
Tue Mar 1 17:37:11 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 44eee659f1c530a684fa2e57a983d962b5980620
      https://github.com/llvm/llvm-project/commit/44eee659f1c530a684fa2e57a983d962b5980620
  Author: Zhihao Yuan <zhihao.yuan at broadcom.com>
  Date:   2022-03-01 (Tue, 01 Mar 2022)

  Changed paths:
    M clang/include/clang/AST/DeclTemplate.h
    M clang/include/clang/AST/PrettyPrinter.h
    M clang/include/clang/Basic/CharInfo.h
    M clang/lib/AST/APValue.cpp
    M clang/lib/AST/ASTDiagnostic.cpp
    M clang/lib/AST/DeclTemplate.cpp
    M clang/lib/AST/Expr.cpp
    M clang/lib/AST/StmtPrinter.cpp
    M clang/lib/AST/TemplateBase.cpp
    M clang/lib/Sema/Sema.cpp
    A clang/test/SemaCXX/cxx2a-nttp-printing.cpp
    A clang/test/SemaTemplate/temp_arg_string_printing.cpp
    M clang/unittests/AST/TypePrinterTest.cpp

  Log Message:
  -----------
  [AST] Print NTTP args as string-literals when possible

C++20 non-type template parameter prints `MyType<{{116, 104, 105, 115}}>` when the code is as simple as `MyType<"this">`. This patch prints `MyType<{"this"}>`, with one layer of braces preserved for the intermediate structural type to trigger CTAD.

`StringLiteral` handles this case, but `StringLiteral` inside `APValue` code looks like a circular dependency. The proposed patch implements a cheap strategy to emit string literals in diagnostic messages only when they are readable and fall back to integer sequences.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D115031




More information about the All-commits mailing list