From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31868 invoked by alias); 6 Mar 2013 09:47:48 -0000 Received: (qmail 31748 invoked by uid 48); 6 Mar 2013 09:47:17 -0000 From: "yurivkhan at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug pch/56549] New: #pragma once ineffective with BOM in include file Date: Wed, 06 Mar 2013 09:47:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: pch X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: yurivkhan at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2013-03/txt/msg00456.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D56549 Bug #: 56549 Summary: #pragma once ineffective with BOM in include file Classification: Unclassified Product: gcc Version: 4.6.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: pch AssignedTo: unassigned@gcc.gnu.org ReportedBy: yurivkhan@gmail.com Created attachment 29594 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=3D29594 Minimal example demonstrating the problem When an include file starts with a UTF-8 byte order mark and is included in= a precompiled header, it is not protected against repeated inclusion. Environment: * Ubuntu 12.04 amd64 * GCC 4.6.3 from Ubuntu repo To reproduce: $ unzip pragma-once-bom.zip $ make The contents of the archive are listed below for convenience of discussion. Foo.h: =3D=3D=3D #pragma once struct Foo {}; =3D=3D=3D stable.h: =3D=3D=3D #include "Foo.h" =3D=3D=3D main.cpp: =3D=3D=3D #include "stable.h" int main() { Foo foo; } =3D=3D=3D Makefile: =3D=3D=3D all: main.o pragma-once.gch/c++: stable.h Foo.h @test -d pragma-once.gch || mkdir pragma-once.gch g++ -x c++-header -c stable.h -o pragma-once.gch/c++ main.o: main.cpp stable.h Foo.h pragma-once.gch/c++ g++ -c -include pragma-once -o main.o main.cpp clean: @rm -rf pragma-once.gch main.o =3D=3D=3D Expected behavior: =3D=3D=3D $ make g++ -x c++-header -c stable.h -o pragma-once.gch/c++ g++ -c -include pragma-once -o main.o main.cpp =3D=3D=3D Observed behavior: =3D=3D=3D $ make g++ -x c++-header -c stable.h -o pragma-once.gch/c++ g++ -c -include pragma-once -o main.o main.cpp In file included from stable.h:1:0, from main.cpp:1: Foo.h:3:8: error: redefinition of =E2=80=98struct Foo=E2=80=99 Foo.h:3:8: error: previous definition of =E2=80=98struct Foo=E2=80=99 make: *** [main.o] Error 1 =3D=3D=3D Workarounds/observations: * If the header file does not contain a BOM, the problem does not occur. * With include guards instead of #pragma once, the problem does not occur. * In a real project, changing an #include to #include in the precompiled header stable.h, or changing an #include to #include "Foo.h" in a different header included by stable= .h, also fixes the immediate problem.