$ gcc --version
gcc (GCC) 3.2.3 20030331 (Debian prerelease)
Imagine that I have a project directory "project" and a subdirectory "memory"
with some file to manage my memory.
If I have a cpp file with #include <memory> and the gcc command line have -
Iproject g++ will take my memory directory instead of the standard memory
header. It should know that my memory is not a file but a directory and try to
find another memory (the standard one).
I didn't find somewhere in the ANSI C++ doc an explaination if it's a bug or a
I cannot reproduce this on 3.0.4, 3.2.2., 3.2.3, 3.3.1 (20030616), or the mainline
(20030618) with the instructions you gave, but I could reproduce it on 2.95.3, make sure
that g++ has been updated also because it looks like it has not.
This bug is still present on mingw32 hosts on both 3.4.0 and trunk.
It is caused by the behaviour of open() in cppfiles:open_file(). On mingw32
_any_ attempt to open() a directory fails and sets errno to EACCES, regardless
of permissions. So, rather than continuing the search for a valid header, the
search fails with "Permission denied"
This will fix:
RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
retrieving revision 1.209
diff -c -3 -p -r1.209 cppfiles.c
*** cppfiles.c 5 May 2004 18:25:52 -0000 1.209
--- cppfiles.c 19 May 2004 21:18:52 -0000
*************** open_file (_cpp_file *file)
*** 233,238 ****
--- 233,246 ----
else if (errno == ENOTDIR)
errno = ENOENT;
+ /* An attempt to open() a directory may fail and set errno to EACCES.
+ On __MINGW32__ host an attempt to open() _any_ directory will do this.
+ Check and reset errno to ENOENT. */
+ else if (errno == EACCES
+ && stat (file->path, &file->st) == 0
+ && S_ISDIR (file->st.st_mode))
+ errno = ENOENT;
file->err_no = errno;
Reopening since this is still an issue.
(In reply to comment #3)
> Reopening since this is still an issue.
Though only on mingw32.
This patch seems fairly reasonable to me, though not perfect.
It will reset errno if stat() fails, which, while probably not
fatal, is still a bit troubling.
I am inclined to think that this is an operating system bug and should be worked around in the mingw32 libraries, not in cpplib.
2007-06-09 Vladimir Prus <email@example.com>
* files.c (open_file): Account for the
fact that on windows, opening a directory gives