[PATCH] D94259: [clangd] Fix type printing in the presence of qualifiers

Adam Czachorowski via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 7 12:51:15 PST 2021


adamcz created this revision.
Herald added subscribers: usaxena95, kadircet, arphaman.
adamcz requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang.

When printing QualType with qualifiers like "const", or pointing to an
elaborated type, we would print garbage like:

  std::const std::vector<int>&

with the initial std:: being calculated correctly, but inserted in the
wrong place and the second std:: not removed (due to elaborated type).

This affected, among others, ExtractFunction and ExpandAuto tweaks.

This change introduces a new callback to PrintingPolicy, which allows us
to influence the printing of namespace qualifiers. In the future, the
same callback can be used to improve handling of "using namespace"
directives as well.

Fixes:

  https://github.com/clangd/clangd/issues/640 (ExtractFunction)
  https://github.com/clangd/clangd/issues/264 (ExpandAuto)
  First point of https://github.com/clangd/clangd/issues/524


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94259

Files:
  clang-tools-extra/clangd/AST.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExpandAutoTypeTests.cpp
  clang-tools-extra/clangd/unittests/tweaks/ExtractFunctionTests.cpp
  clang/include/clang/AST/PrettyPrinter.h
  clang/lib/AST/TypePrinter.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94259.315217.patch
Type: text/x-patch
Size: 4665 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210107/50834e35/attachment.bin>


More information about the cfe-commits mailing list