Closed
Bug 1187486
Opened 9 years ago
Closed 9 years ago
clang-plugin's implicit constructor analysis misses templated constructors
Categories
(Developer Infrastructure :: Source Code Analysis, defect)
Developer Infrastructure
Source Code Analysis
Tracking
(firefox42 fixed)
RESOLVED
FIXED
mozilla42
Tracking | Status | |
---|---|---|
firefox42 | --- | fixed |
People
(Reporter: nika, Assigned: nika)
References
Details
Attachments
(11 files)
9.18 KB,
patch
|
ehsan.akhgari
:
review-
|
Details | Diff | Splinter Review |
7.90 KB,
patch
|
Details | Diff | Splinter Review | |
1.76 KB,
patch
|
Details | Diff | Splinter Review | |
5.45 KB,
patch
|
Details | Diff | Splinter Review | |
8.84 KB,
patch
|
Details | Diff | Splinter Review | |
1.14 KB,
patch
|
Details | Diff | Splinter Review | |
1.10 KB,
patch
|
Details | Diff | Splinter Review | |
942 bytes,
patch
|
Details | Diff | Splinter Review | |
1.20 KB,
patch
|
Details | Diff | Splinter Review | |
1.01 KB,
patch
|
Details | Diff | Splinter Review | |
2.46 KB,
patch
|
Details | Diff | Splinter Review |
If we have a class with a templated single argument constructor, like
template <typename I>
nsRefPtr(already_AddRefed<I>& aSmartPtr)
: mRawPtr(aSmartPtr.take())
// construct from |already_AddRefed|
{
}
the clang-plugin currently doesn't complain about the lack of an `explicit` or `MOZ_IMPLICIT` annotation, in spite of the constructor being an implicit constructor.
I think that this is because these items are listed in the definition of the struct as FunctionTemplateDecl rather than CXXConstructorDecl, which means that our analysis misses them. We should be able to get around that by also checking for FunctionTemplateDecls where the template declaration is a CXXConstructorDecl.
In addition, I believe that this could be avoided by using Matchers rather than the current strategy of using the RecursiveASTVisitor, as the RecursiveASTVisitor, by default, doesn't enter template instantiations, and if we just directly match CXXConstructorDecls, we will match those produced by template instantiations as well.
Assignee | ||
Comment 1•9 years ago
|
||
We can't land this yet because there are loads of violating code in the codebase right now which need to be fixed first, but this is the change to the plugin to get started.
We should open dependent issues for each of the constructors we discover this way, but I don't have time to do that right now.
Attachment #8638797 -
Flags: review?(ehsan)
Comment 2•9 years ago
|
||
Comment on attachment 8638797 [details] [diff] [review]
Update the clang plugin to detect templated implicit constructors
Review of attachment 8638797 [details] [diff] [review]:
-----------------------------------------------------------------
::: build/clang-plugin/clang-plugin.cpp
@@ +746,5 @@
> + // We don't want deleted constructors.
> + !Node.isDeleted();
> +}
> +
> +AST_MATCHER(CXXConstructorDecl, isNotExplicitlyImplicit) {
Please create a positive predicate here (isImplicit) and in the matcher code, use unless(isImplicit()).
Attachment #8638797 -
Flags: review?(ehsan) → review+
Assignee | ||
Comment 3•9 years ago
|
||
Assignee | ||
Comment 4•9 years ago
|
||
Assignee | ||
Comment 5•9 years ago
|
||
Assignee | ||
Comment 6•9 years ago
|
||
Assignee | ||
Comment 7•9 years ago
|
||
Assignee | ||
Comment 8•9 years ago
|
||
Assignee | ||
Comment 9•9 years ago
|
||
Assignee | ||
Comment 10•9 years ago
|
||
Assignee | ||
Comment 11•9 years ago
|
||
Comment 12•9 years ago
|
||
Comment on attachment 8638797 [details] [diff] [review]
Update the clang plugin to detect templated implicit constructors
Actually, as you can see from the change you had to make to JSCompartment, this analysis is not 100% correct, since it only needs to look at declarations in the body of the class, not definitions of constructors.
Attachment #8638797 -
Flags: review+ → review-
Comment 13•9 years ago
|
||
This patch will help fix the issue I mentioned above.
Updated•9 years ago
|
Comment 14•9 years ago
|
||
Comment 15•9 years ago
|
||
I fixed up the patch to address my own comments and landed it for you.
Assignee | ||
Comment 16•9 years ago
|
||
(In reply to :Ehsan Akhgari (not reviewing patches, not reading bugmail, needinfo? me!) from comment #15)
> I fixed up the patch to address my own comments and landed it for you.
Thanks :)
Comment 17•9 years ago
|
||
Comment 18•9 years ago
|
||
Comment 19•9 years ago
|
||
Status: NEW → RESOLVED
Closed: 9 years ago
status-firefox42:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla42
Updated•7 years ago
|
Product: Core → Firefox Build System
Updated•2 years ago
|
Product: Firefox Build System → Developer Infrastructure
You need to log in
before you can comment on or make changes to this bug.
Description
•