From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9306E3858C5E; Wed, 5 Jul 2023 11:30:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9306E3858C5E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688556600; bh=zsONseQXLiFINCvhrlWyNi47KxZHYafEUIutC+onZHM=; h=From:To:Subject:Date:From; b=Tl8UoK79mfvoxlTtPaVjDWINJswKoRm9Jo2gRq0XLzR46jN+vLre+3bgkTst720Pt 4QUers2mFagMHaBHJocqjVoWG3BPK0NlQwXENa8zgezmJwLnxbw5FDrW3P89qShiHK UPW2QPyUDqlgwdcG+FUrTqclputsPkhT78bQscsM= From: "provisorisch at online dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug preprocessor/110558] New: __has_include argument expansion results in unexpected filename Date: Wed, 05 Jul 2023 11:29:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: preprocessor X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: provisorisch at online dot de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D110558 Bug ID: 110558 Summary: __has_include argument expansion results in unexpected filename Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: preprocessor Assignee: unassigned at gcc dot gnu.org Reporter: provisorisch at online dot de Target Milestone: --- Hello! I am building a path to an include file using a function like macro and then checking if the file exists using __has_include. However, if the argument to that macro is padded with spaces it will fail to find the file. Here an example with following 2 files in the same directory: my.header.h: -------- #pragma message("included my.header.h") -------- test.c: -------- #ifndef USE_IMPL # define USE_IMPL my #endif #define STRINGIFY_(X) #X #define STRINGIFY(X) STRINGIFY_(X) #define MAKE_INCLUDE_PATH_(IMPL, NAME) STRINGIFY(IMPL.NAME) #define MAKE_INCLUDE_PATH(NAME) MAKE_INCLUDE_PATH_(USE_IMPL, NAME) // checking __has_include with spaces #if __has_include(MAKE_INCLUDE_PATH( header.h )) // this will return false! # pragma message("\""MAKE_INCLUDE_PATH( header.h )"\" exists") #else # pragma message("\""MAKE_INCLUDE_PATH( header.h )"\" does NOT exist!") // except it does #endif #include MAKE_INCLUDE_PATH( header.h ) // works nonetheless // checking __has_include without spaces #if __has_include(MAKE_INCLUDE_PATH(header.h)) // works # pragma message("\""MAKE_INCLUDE_PATH(header.h)"\" exists") #else # pragma message("\""MAKE_INCLUDE_PATH(header.h)"\" does NOT exist!") #endif #include MAKE_INCLUDE_PATH(header.h) int main() { return 0; } -------- Then to compile: # gcc -Wall -Wextra test.c=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20 =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20 test.c:14:12: note: =E2=80=98#pragma message: "my.header.h" does = NOT exist!=E2=80=99 14 | # pragma message("\""MAKE_INCLUDE_PATH( header.h )"\" does NOT exist!") // except it does | ^~~~~~~ In file included from test.c:16: my.header.h:1:9: note: =E2=80=98#pragma message: included my.header.h=E2=80= =99 1 | #pragma message("included my.header.h") | ^~~~~~~ test.c:20:12: note: =E2=80=98#pragma message: "my.header.h" exists=E2=80=99 20 | # pragma message("\""MAKE_INCLUDE_PATH(header.h)"\" exists") | ^~~~~~~ In file included from test.c:24: my.header.h:1:9: note: =E2=80=98#pragma message: included my.header.h=E2=80= =99 1 | #pragma message("included my.header.h") | ^~~~~~~ The first __has_include fails to find "my.header.h" but the subsequent #inc= lude works. The second __has_include works as expected. Using strace I noticed that an extra space character ended up in the filena= me: openat(AT_FDCWD, "my. header.h", O_RDONLY|O_NOCTTY) =3D -1 ENOENT (No such = file or directory) I would have expected the first __has_include to behave like the second one= .=