-
Notifications
You must be signed in to change notification settings - Fork 128
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't set init and init style of a declaration manually #1232
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
|
||
// Clang expects direct inits to be wrapped either in InitListExpr or | ||
// ParenListExpr. | ||
if (DirectInit && !isa<InitListExpr>(Init) && !isa<ParenListExpr>(Init)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: no header providing "clang::isa" is directly included [misc-include-cleaner]
if (DirectInit && !isa<InitListExpr>(Init) && !isa<ParenListExpr>(Init))
^
f2919dd
to
dcfbee8
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1232 +/- ##
==========================================
+ Coverage 94.64% 94.66% +0.02%
==========================================
Files 51 51
Lines 8890 8886 -4
==========================================
- Hits 8414 8412 -2
+ Misses 476 474 -2
|
837b88d
to
3b6762b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-tidy made some suggestions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty awesome. See comments inline.
// not reset the init and we have to do it manually. | ||
VD->setInit(nullptr); | ||
m_Sema.ActOnUninitializedDecl(VD); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does ActOnUninitializedDecl
set the InitStyle, too? If so we should update the comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does init style matter when it comes to uninitialized decls?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Depends on what clang does... Probably does not but then we need to update the documentation comment of SetDeclInit
.
4d8732f
to
4dabcd7
Compare
4dabcd7
to
c373885
Compare
@@ -16,6 +16,8 @@ | |||
#include "clang/Sema/ParsedAttr.h" | |||
#include "clang/Sema/Sema.h" | |||
#include <array> | |||
#include <clang/AST/Type.h> | |||
#include <llvm/ADT/StringRef.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should put these before array and sort alphabetically.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried ordering everything alphabetically but clang-format reverted all changes. I separated the includes into different blocks, clang-format seems to be okay with this. I hope this is better.
@@ -5,6 +5,7 @@ | |||
|
|||
#include "clang/AST/TemplateName.h" | |||
#include "clang/Sema/Lookup.h" | |||
#include <clang/AST/Decl.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That needs to be sorted..
4f17027
to
9415eca
Compare
Initialization styles should not be set manually, instead, they should be deduced by clang based on the types of the declaration and init, as well as on whether the declaration is direct. e.g. direct initialization of `std::vector vec` with `other` should look like ``` std::vector vec(other); ``` and not ``` std::vector vec = other; ```
Sometimes we initialize declarations using ``Decl::setInit``, which is a low-level function used by clang internally. This commit introduces a wrapper of ``Sema::AddInitializerToDecl`` called ``SetDeclInit``.
9415eca
to
cf8540b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
This PR addresses 2 issues:
e.g. direct initialization of
std::vector vec
withother
should look likeand not
Decl::setInit
, which is a low-level function used by clang internally. This PR introduces a wrapper ofSema::AddInitializerToDecl
calledSetDeclInit
.