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.
As reported in issue #981, using std::regex in IWYU has caused a
tremendous performance regression for large mapping files containing
regex mappings.
$ cat t.cc
#include <string>
# with llvm::Regex
$ time include-what-you-use -Xiwyu --mapping_file=qt5_11.imp t.cc
...
real 0m0,529s
user 0m0,509s
sys 0m0,020s
# with std::regex
$ time include-what-you-use -Xiwyu --mapping_file=qt5_11.imp t.cc
...
real 0m29,870s
user 0m29,717s
sys 0m0,012s
qt5_11.imp contains 2300+ regex mappings, and <string> has a bunch of
includes, so this is a good testbed for regular expression engines, but
over 50x slower is not the result we were hoping for.
The reason we switched to std::regex was to get support for negative
lookaround (llvm::Regex does not have it), but exotic regexes in
mappings are pretty rare, and this is a significant performance hit.
Introduce a --regex option to select regex dialect, with documented
tradeoffs. Put the default back to LLVM's fast implementation.
This fixes issue #981.
Sometimes for debugging and testing, it helps to be able to tweak IWYU behavior
beyond the log verbosity.
Add a free-form --debug argument that takes a comma-separated list of flag
names. No validation is performed on these flags, they just serve as a global
switchboard to enable/disable custom behavior.
Note that these are not intended as a replacement for switches in general, just
as a support structure for quickly adding conditional debug behavior while
troubleshooting.
Two new options:
--error: sets the exit code to use if there are IWYU violations
--error_always: sets the exit code to use whether there are IWYU
violations or not
Add tests to capture all relevant combinations of
(no warnings, warnings) x
(--error, --error_always) x
(explicit arguments, default values)
and make sure --error_always overrides --error.
Exit with EXIT_FAILURE if the command-line arguments are invalid or
Clang fails to parse the input. Otherwise exit with EXIT_SUCCESS.
Add tests to capture this new policy.
Fixes#75 and fixes#494.
Add `--update_comments` option to make IWYU always print the 'why'
#include comments, regardless of whether any include lines need to be
added or removed. With this change, IWYU will update the "// for xyz"
comments as the code changes, preventing the comments from becoming
stale.
The map range iterator returns a `const pair<const string, ...>&`, not the
expected `const pair<string, ...>&`, and the compiler helpfully converts
to a temporary. Make the types match.
Found by Clang's -Wrange-loop-construct
llvm/llvm-project@777180a makes the llvm::StringRef conversion operator
to std::string explicit.
These changes add a call to the str() method to perform the conversion.
Signed-off-by: Andrea Bocci <andrea.bocci@cern.ch>
.moc files are handled by a separate Qt preprocessor called 'moc', which
expands them into C++ code.
They are not C++ in and of themselves, and can't be safely analyzed by
IWYU. The moc preprocessor allegedly suggests to remove unused .moc
includes, so we should leave them alone.
Implement this by pretending '--keep="*.moc"' was passed on the
command-line.
Fixes issue #721.
Several options were incorrectly marked with 'optional_argument', which
means they can take a value argument, but don't have to. We don't have
any options like that.
Fixes issue #663.
This opts in for the more concise syntax introduced in C++17: namespace
a::b { ... }.
Usage of this is especially useful in codebases where existing forward
declarations in nested namespaces already use this form: so the IWYU
suggestion for new forward declarations can be consistent with the
existing ones.
fix_includes.py already handled this, but add a test to maintain this
behavior, too.
The Each construct was nice, but it's outlived its usefulness, the range for
loops are both easier to read and write.
For iteration over maps, we consistently use 'auto' to avoid repeating the map
value type.
This has been a long-standing issue with IWYU (see issues #5, #271 and
probably others) where ConvertToQuotedInclude generates absolute paths
if IWYU is invoked with the current directory different from the source
file path.
This patch moves most path building to use absolute paths and path of
the includer (rather than the cwd) to produce better results.
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
If two paths in the header search set shared the same prefix, IWYU would
sometimes pick the wrong one and produce an invalid quoted include. For
example:
Header search path: /a/foo, /a/foobar
File path: /a/foobar/header.h
This would yield "bar/header.h", as "/a/foo" was considered a basename of
the file path.
We fix this by ensuring all search path entries end with "/" up-front.
I didn't add a test for this, because an end-to-end test would be almost
nonsensical. Once we get the unit test suite up and running, I'd like to
add a test for this there instead.
IWYU now supports a new --pch_in_code switch which indicates the first
include directive in the translation unit is a precompiled header.
Precompiled headers are treated as prefix headers, even though they
were not specified on the command-line, but they can never be removed.
Finally, they sort first in include lists generated by IWYU, because
most compilers require the PCH to be included before anything else.
--prefix_header_includes controls presence of includes and forward declarations
involving files included via command-line option -include. Issue is reported by
Max Dyckhoff.
--no_default_mappings will cause IWYU not to add the default GCC-oriented mappings, to make it easier to build custom mapping suites for other toolchains.
- Remove hard-coded mapping search path in iwyu_globals.cc
- Remove AddMappingFileSearchPath
- Add private AddMappingsFromFile to handle search path building
- Push search path scanning out into free function FindFileInSearchPath
- Less, but more focused logging.
- Fix indentation in iwyu_include_picker.cc
- Simplify parsing code by making current_node a Node* instead of a Node&
- iwyu.gcc.imp is no longer added automatically if no mapping file is specified
- Instead, the defaults are hard-coded in iwyu_include_picker.cc
- Fix some 80-column overruns
Search for mapping files:
- in the current working directory;
- in the directory where IWYU executable is located;
- in the directory where another discovered mapping file is located.
This was motivated by an attempt to understand how iwyu_ast_util.cc
depended on iwyu_output, which turned out to be the use of VERRS.
I split the VERRS definition out into a separate iwyu_verrs module.
In the fallout from this I discovered some circular dependencies
that this CL attempts to disentangle.
R=csilvers
DELTA=603 (349 added, 222 deleted, 32 changed)
Revision created by MOE tool push_codebase.
MOE_MIGRATION=3892