Conrad Poelman via llvm-dev
2019-Oct-31 19:59 UTC
[llvm-dev] Initializer expression SourceRange differs between c++14 and c++17, affecting clang-tidy
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>
Sjoerd Meijer via llvm-dev
2019-Nov-01 09:25 UTC
[llvm-dev] Initializer expression SourceRange differs between c++14 and c++17, affecting clang-tidy
I guess you might have more luck with this query on the Clang mailing list:
cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
________________________________
From: llvm-dev <llvm-dev-bounces at lists.llvm.org> on behalf of Conrad
Poelman via llvm-dev <llvm-dev at lists.llvm.org>
Sent: 31 October 2019 19:59
To: llvm-dev at lists.llvm.org <llvm-dev at lists.llvm.org>
Subject: [llvm-dev] Initializer expression SourceRange differs between c++14 and
c++17, affecting clang-tidy
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<https://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/20191101/40a97531/attachment.html>