[llvm-dev] Initializer expression SourceRange differs between c++14 and c++17, affecting clang-tidy

Conrad Poelman via llvm-dev llvm-dev at lists.llvm.org
Thu Oct 31 12:59:42 PDT 2019


When parsing a named declaration with an equals sign with clang -std
c++11/14, clang builds an initializer expression whose SourceRange covers
from variable name through the end of the initial value:
  std::string foo = "bar";
              -----------

When parsing the same code with clang -std c++17/2x, the initializer
expression's SourceRange only includes the initial value itself, and not
the variable name or the equals sign:
  std::string foo = "bar";
                    -----

If the string is initialized using parentheses rather than an equals sign,
in all of c++11/14/17/2x the initializer expression's SourceRange includes
the variable name and both parentheses:
  std::string foo("bar");
              ----------

This difference breaks clang-tidy's readability-remove-redundant-string
<https://clang.llvm.org/extra/clang-tidy/checks/readability-redundant-string-init.html>
for c++17 and c++2x, as described in at reviews.llvm.org/D69238. Is this
SourceRange difference intentional, and if not does anyone have thoughts on
how to make the SourceRange consistent across C++ standards? Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20191031/1d144164/attachment.html>


More information about the llvm-dev mailing list