[Bug preprocessor/80005] New: cpp expands __has_include() filename parts
tim+gcc-bugzilla at centricular dot com
gcc-bugzilla@gcc.gnu.org
Sat Mar 11 12:58:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80005
Bug ID: 80005
Summary: cpp expands __has_include() filename parts
Product: gcc
Version: 6.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: preprocessor
Assignee: unassigned at gcc dot gnu.org
Reporter: tim+gcc-bugzilla at centricular dot com
Target Milestone: ---
gcc (Debian 6.3.0-4) 6.3.0 20170121
cpp (Debian 6.3.0-4) 6.3.0 20170121
Also happens with latest gcc7 snapshot on https://gcc.godbolt.org/
Linux 4.9.0-1-amd64 #1 SMP Debian 4.9.2-2 (2017-01-12) x86_64 GNU/Linux
I believe this is a gcc preprocessor bug. It works fine with clang fwiw.
1) Precondition:
/usr/include/linux/memfd.h exists (it does).
2) Source code to reproduce:
----------------------------------------------------
#ifdef __has_include
#if !__has_include(<linux/memfd.h>)
#error "Header 'linux/memfd.h' could not be found"
#endif
#endif
----------------------------------------------------
3) Steps to reproduce:
$ cpp inctest.c out
inctest.c:3:12: error: #error "Header 'linux/memfd.h' could not be found"
$ strace -f cpp inctest.c out 2>&1 | grep memfd.h | grep /usr/include
[pid 8935] open("/usr/include/1/memfd.h", O_RDONLY|O_NOCTTY) = -1 ENOENT
Note that linux/memfd.h was expanded to 1/memfd.h here.
Presumably #define linux 1 is one of the compiler/preprocessor predefines?
I believe it should not expand filenames (clang doesn't, fwiw).
Adding a #undef linux "fixes" the issue.
More information about the Gcc-bugs
mailing list