Bug 11242 - [mingw32] #include <memory> takes my memory directory instead of the standard memory header file
Summary: [mingw32] #include <memory> takes my memory directory instead of the standard...
Alias: None
Product: gcc
Classification: Unclassified
Component: preprocessor (show other bugs)
Version: 3.2.3
: P2 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
Keywords: rejects-valid
Depends on:
Reported: 2003-06-18 15:35 UTC by lecroart
Modified: 2012-06-04 02:30 UTC (History)
4 users (show)

See Also:
Host: mingw32
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description lecroart 2003-06-18 15:35:35 UTC
$ 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 

Comment 1 Andrew Pinski 2003-06-18 19:59:00 UTC
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.
Comment 2 Danny Smith 2004-05-19 21:27:45 UTC
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:

Index: cppfiles.c
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;
    return false;
Comment 3 Andrew Pinski 2006-10-23 22:31:13 UTC
Reopening since this is still an issue.
Comment 4 Andrew Pinski 2006-10-23 22:32:10 UTC

(In reply to comment #3)
> Reopening since this is still an issue.

Though only on mingw32.
Comment 5 Tom Tromey 2007-01-08 01:14:59 UTC
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.
Comment 6 Zack Weinberg 2007-04-21 02:56:36 UTC
I am inclined to think that this is an operating system bug and should be worked around in the mingw32 libraries, not in cpplib.
Comment 7 Danny Smith 2007-06-17 23:40:30 UTC
Fixed by:
2007-06-09  Vladimir Prus  <vladimir@codesourcery.com>

	* files.c (open_file): Account for the
        fact that on windows, opening a directory gives