This little beauty would cause an assertion failure in GetCanonicalName:
printf "#include <stdio.h>" | include-what-you-use -c -x c -
Special-case '<stdin>' like we do with '<built-in>'.
Fixes issue #1105.
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>
This fixes a case where IWYU would suggest include paths with ".." where
a simpler non-".." path would suffice. E.g.
// a.h
struct Symbol {};
// foo/b.h
#include "../a.h"
// main.c
#include "foo/b.h"
Symbol s;
IWYU would suggest we should include "foo/../a.h" from main.c here. This
is correct, but inelegant.
After this patch, we'll suggest "a.h" directly. Unfortunately, this is
broken in the face of symlinks (example cut from bug report) --
akuli@Akuli-Desktop:~$ ln -s /usr a
akuli@Akuli-Desktop:~$ file a
a: symbolic link to /usr
akuli@Akuli-Desktop:~$ file lib
lib: cannot open `lib' (No such file or directory)
akuli@Akuli-Desktop:~$ file a/../lib
a/../lib: directory
akuli@Akuli-Desktop:~$
-- but I suspect this is more unusual than relative includes.
Fixes issue 690.
This is part of Google's original open-sourcing of IWYU.
They keep third-party libraries in a directory called, well,
'third-party', so there was lots of special casing for code in
that directory.
Remove that code, unit tests covering it and explicit mappings.
Keep one special case for allowing include cycles for files with
'internal/' in the name, to avoid breaking the include_cycle test
case. Not sure what to do about that longer term, but I didn't want to
remove the test case right now.
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.
NULL/0 -> nullptr
C standard library include -> C++ counterparts
Use override keyword
Range for loops in selected places
Occasional use of auto
Remove unused usings
Remove unnecessary uses of c_str()
Closing comments for anonymous namespaces
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.
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.
- No longer necessary to define _POSIX_ for MSVC builds
- Remove some cruft from port.h
- Remove unused direct.h/unistd.h includes
- Clean up includes in iwyu_path_util.h
- No functionality change intended
- Tested on Win32/MSVC + Linux/GCC
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.