HaveF / include-what-you-use

Automatically exported from code.google.com/p/include-what-you-use
Other
0 stars 0 forks source link

iwyu removes differently named headers with declarations even despite -Wmissing-declarations -Werror #179

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Issue is present with C code. In project I participate gcc options 
-Wmissing-declarations -Werror are required, also declarations in header files 
can be split into public and those available only inside the repository 
(private), with whose iwyu has a problem.

Problem can be reproduced on attached files. iwyu gives output:
$ iwyu StringTest.c -Wmissing-declarations -Werror
StringTest.c should add these lines:

StringTest.c should remove these lines:
- #include "StringTestPrivate.h"  // lines 1-1

The full include-list for StringTest.c:
#include <stdlib.h>                     // for calloc
#include <string.h>                     // for memcpy

---

Clearly applying such fix would lead to:
$ gcc StringTest.c -Wmissing-declarations -Werror
StringTest.c:6:46: error: no previous declaration for ‘memcpytest’ 
[-Werror=missing-declarations]
 __attribute__ ((visibility ("hidden"))) int *memcpytest(int **var, int **val) {
                                              ^
cc1: all warnings being treated as errors

With these flags I expect iwyu to include headers providing required 
declarations regardless of where they are.

Tested on Ubuntu 14.04
$ iwyu --version
include-what-you-use 0.3 (590) based on clang version 3.5.0 
(tags/RELEASE_350/final)
$ gcc --version
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2

Original issue reported on code.google.com by mrzygloc...@gmail.com on 3 Mar 2015 at 1:16

Attachments:

GoogleCodeExporter commented 9 years ago
Thanks for the report, Marcin, it is a tricky use case. As far as I remember 
IWYU doesn't look at warning flags and visibility attributes. It will be 
interesting to try to fix this issue.

Do you have clang on your system? Because for me `clang StringTest.c 
-Wmissing-declarations -Werror` doesn't show any errors. I wonder if clang and 
gcc behave differently on this code.

Original comment by vsap...@gmail.com on 10 Mar 2015 at 5:27

GoogleCodeExporter commented 9 years ago
clang indeed shows nothing, so it's apparently behaving differently than gcc. 
Maybe that's because clang's intention is not to duplicate additional gcc's 
warnings (because they aren't breaking compilation), as they might be detected 
with run of gcc - and clang is doing just error detection anyway. IWYU on the 
other hand intends to modify source code and apparently there are compiler 
flags that modify expectations on its output.

$ clang --version
Ubuntu clang version 3.4-1ubuntu3 (tags/RELEASE_34/final) (based on LLVM 3.4)
Target: x86_64-pc-linux-gnu
Thread model: posix

Original comment by mrzygloc...@gmail.com on 10 Mar 2015 at 11:17

GoogleCodeExporter commented 9 years ago
Thank you for testing it, Marcin. I don't know why clang and gcc have different 
behaviour in this case, but it's useful to know.

Original comment by vsap...@gmail.com on 14 Mar 2015 at 7:05