Commit Graph

23 Commits

Author SHA1 Message Date
Kim Gräsman b65c4b63a7 Format all lines with leading =
This is the unadorned output of:

    git grep -En "^\s*=" -- ':!tests/*' | grep-format

There are some examples with comments between the variable name and the
'=' that clang-format left unchanged.

No functional change.
2023-01-07 12:27:16 +01:00
Kim Gräsman 890a3150d7 Format all return statements on their own line
This is the unadorned result of:

    git grep -En "\w.*return .*;" -- ':!tests/*' | grep-format

Having return statements on their own line makes it easier to set
breakpoints in most debuggers.

No functional change.
2023-01-07 12:27:16 +01:00
Kim Gräsman cced95dba5 Do not crash if IsInHeader is called for builtin
In very particular circumstances (see test case), VisitFunctionDecl
would see a function definition that was an implicit constructor of a
builtin (va_list_tag).

Rather than crashing for implicit code, just say it's not in a header.

This feels a little questionable, because depending on how IsInHeader is
used, it might be misleading that it returns false for builtins/implicit
code. But I think it makes sense for now.

Fixes issue #1162.
2022-12-30 12:45:24 +01:00
Bolshakov 862812049a Avoid 'autocast' reporting for function definition
A function may just transmit passed-by-reference parameter somewhere.
Requirement to explicitly write forward declaration in the same file
(.cpp-file) to avoid '#include' suggestion is impractical when that type
is already fwd-declared in the corresponding header.
'Autocast' may still make sense for header-defined functions, due to
unlimited number of possible callers, so analysis of those fuctions
is kept.

Both function declaration site handling and call site handling
are changed.
2022-10-08 16:17:50 +02:00
Kim Grasman 0dc480dba3 Update for Clang r341573
Clang finally made the leap and harmonized all the Loc methods:

* getLocStart, getStartLoc -> getBeginLoc
* getLocEnd -> getEndLoc

r341573 removes the deprecated names, so update the few uses we had.
2018-09-12 07:10:59 +02:00
EugeneZelenko eb7f5d1ef0 Fix Clang-tidy warnings
- readability-redundant-member-init warnings
- modernize nested templates; '> >'
- modernize-use-default warnings
2016-11-16 21:04:24 +01:00
EugeneZelenko e05d81f32d Fix some Clang-tidy warnings
NULL/0 -> nullptr
C standard library include -> C++ counterparts
Occasional use of auto
Explicit strcmp return value check
Remove unused usings
Closing comments for anonymous namespaces
2016-06-07 21:49:33 +02:00
Kim Grasman 0f76ccbf0a Fix IsInScratchSpace so it actually works.
Scratch space locations look like "<scratch space>:line:col", but we compared
directly against "<scratch space>", which would always fail.

Move macro-arg-concatenation test from badinc to macro_location to make it
easier to detect failures in the future.
2016-03-20 15:49:33 +01:00
Kim Grasman 178b04f014 Fix #127: Improve macro location logic
- Rename GetUseLocationForMacroExpansion -> GetCanonicalUseLocation
- Let macro authors forward-declare symbols to push responsibility
  to expansion
- Symbols passed as arguments to macros are now attributed to expansion

Second commit attempt, with explicit use of spelling-location for
uses attributed to macro definition.
2016-03-15 22:21:39 +01:00
Kim Grasman 380c96abb1 Revert "Fix #127: Improve macro location logic"
This reverts commit 32d04eecd5.

Unexpectedly broke the badinc test on Ubuntu/GCC.
2016-03-11 08:06:56 +01:00
Kim Grasman 32d04eecd5 Fix #127: Improve macro location logic
- Rename GetUseLocationForMacroExpansion -> GetCanonicalUseLocation
- Let macro authors forward-declare symbols to push responsbility to expansion
- Symbols passed as arguments to macros are now attributed to expansion
2016-03-10 19:18:59 +01:00
Kim Grasman d5cf673c5a Better location reporting for unary operators
The location for the use of 'x' in 'sizeof(*(x))' will now point to 'x'
instead of '*'. This helps simplify future changes for reporting of macro
locations.

No functional change.
2016-03-10 19:03:56 +01:00
Volodymyr Sapsai fd4f7d163f Simplify handling include filename location in macro. 2012-12-02 21:50:10 +00:00
Volodymyr Sapsai f8fd069e44 Fixed file heading comments not matching the filename (issue #83). Patch by Ryan Pavlik.
Also made the length of the first line to be 80 characters where possible.
2012-11-25 22:09:37 +00:00
Volodymyr Sapsai 1e43b5df1a Instead of include location use included filename location in
GetIncludeNameAsTyped. In case of macro use spelling location (issue #67).
2012-06-12 20:40:02 +00:00
csilvers+iwyu 5ca17d139e Include-what-you-use fixit -- fix #includes on iwyu itself.
R=csilvers
DELTA=123  (22 added, 5 deleted, 96 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1732
2011-05-04 18:30:53 +00:00
csilvers+iwyu 3d55404056 Include-what-you-use fixes by running it on itself.
R=dsturtevant,csilvers
	DELTA=215  (135 added, 45 deleted, 35 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1731
2011-05-04 18:29:59 +00:00
csilvers+iwyu ed381497a3 Add a test to protect against syntax errors in main(). Also
test some main()-invariant logic while I'm at it.

DELTA=19  (16 added, 0 deleted, 3 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1409
2011-04-13 03:11:35 +00:00
csilvers+iwyu ba169a5419 A few small cleanups based on wan's feedback. No functional
change.

R=wan
DELTA=35  (8 added, 0 deleted, 27 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1350
2011-04-12 05:02:20 +00:00
csilvers+iwyu 37c67ac363 I was not correctly getting the location for member-exprs. I
thought I was saying the location is where the . (or ->) is,
which is what I want, but clang doesn't actually expose that.
So I have go through some hoops to try to figure it out.

We were actually seeing a problem with this when running:

blaze build --host_cpu=k8 --compile_only -k --crosstool_top=//third_party/llvm/crosstool --plugin=//devtools/maintenance/include_what_you_use:run_iwyu //gws/plugins/local/src:enhanced_listing_ad

It has 'msg_->MSG_foo' in it, where MSG_foo is a macro.  We
were attributing this use to the file defining MSG_foo, rather
than to us.  With this change, we properly attribute it to us.

R=dsturtevant
DELTA=150  (125 added, 6 deleted, 19 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=1347
2011-04-12 05:00:17 +00:00
csilvers+iwyu 55552e6cbe It turns out the problem with failing tests wasn't due to
handling of elaborated types at all, but instead was because
RecursiveASTVisitor changed from calling
TraverseNestedNameSpecifier to TraverseNestedNameSpecifierLoc
for most nns's.  We didn't subclass
TraverseNestedNameSpecifierLoc so we were missing a lot of
NNS's.

This CL backs out the previous change, and replaces it with code to
intercept and handle NNSLoc's.  The end result is the same --
badinc.cc is down to two failing tests (which are perhaps
unrelated to the clang upgrade, but instead due to changes to
iwyu itself).

I also fixed up the last two remaining badinc failures.
They were both caused by a type that I expected to be a
TemplateSpecializationType, but was actually an
ElaboratedType, because it was std::vector<...>.  (So maybe
there *was* a change wrt elaborated types in the clang code.)
I audited iwyu_ast_util.h to make sure I was putting
RemoveElaboration() calls in all the necessary places.
Hopefully I got them all...

In tracking this down, I found another bug in the same area
(nested template specializations), but I'll deal with that in
a different CL.

R=dsturtevant
DELTA=132  (75 added, 43 deleted, 14 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=895
2011-03-18 02:53:09 +00:00
csilvers+iwyu 70f296f134 The intends-to-provide code wasn't working quite right. If I
#include <vector>, then I intend-to-provide <vector>: you
don't have to #include <vector> just because I use it in my
(presumably templated) code, because I'm #including <vector>
for you.  However, this logic runs before the private->public
mappings are done, so you're never actually wondering about
<vector>, you're wondering about <bits/stl_vector.h>.

In other words, if I'm #including <vector>, it's not to get
the symbols just provided by <vector>, but to get the symbols
provided by all the private headers that map to <vector> as
well.

I've changed the code that populates the intends-to-provide
map to handle this case.  Now we have many fewer instances of
iwyu randomly deciding that you need to #include a file that
is only used in templated code.  I think there are more
improvements to make in this area, but that will have to wait
for another day.

Another problem is that when we decided a template was
responsible for a decl, because it intends-to-provide it, we
were ignoring the decl, rather than keeping it and just
assigning its use to the template.  Usually this is harmless,
but it could result in us deciding that the decl isn't used
anywhere at all, and removing an #include (from the template
file) that should be kept.  In addition to fixing the relevant
code, I've updated a test to make sure that doesn't happen.

Testing showed up another issue, which is that the code for
determining decl locations was correctly handling templated
classes but not templated functions.  This is now fixed.
Fixing it, unfortunately, made visible a known weakness in
IntendsToProvide, involving its ability to guess whether a
file actually intends to provide a definition for its symbols
or not, which is now a new TODO in badinc.cc.

R=dsturtevant
DELTA=285  (196 added, 66 deleted, 23 changed)


Revision created by MOE tool push_codebase.
MOE_MIGRATION=736
2011-03-04 00:28:14 +00:00
csilvers dee92b5e0a Initial release! Grains of salt not included. 2011-02-04 22:28:15 +00:00