public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug pch/56549] New: #pragma once ineffective with BOM in include file
@ 2013-03-06  9:47 yurivkhan at gmail dot com
  2013-03-06  9:52 ` [Bug pch/56549] " yurivkhan at gmail dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: yurivkhan at gmail dot com @ 2013-03-06  9:47 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56549

             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=29594
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:
===
<BOM>#pragma once

struct Foo {};
===

stable.h:
===
#include "Foo.h"
===

main.cpp:
===
#include "stable.h"

int main() { Foo foo; }
===

Makefile:
===
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
===

Expected behavior:

===
$ make
g++ -x c++-header -c stable.h -o pragma-once.gch/c++
g++ -c -include pragma-once -o main.o main.cpp
===

Observed behavior:

===
$ 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 ‘struct Foo’
Foo.h:3:8: error: previous definition of ‘struct Foo’
make: *** [main.o] Error 1
===

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 <FooLib/Foo.h> to #include
<FooLib/./Foo.h> in the precompiled header stable.h, or changing an #include
<FooLib/Foo.h> to #include "Foo.h" in a different header included by stable.h,
also fixes the immediate problem.


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-10-06 12:13 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-06  9:47 [Bug pch/56549] New: #pragma once ineffective with BOM in include file yurivkhan at gmail dot com
2013-03-06  9:52 ` [Bug pch/56549] " yurivkhan at gmail dot com
2013-09-25  5:22 ` woodroof at gmail dot com
2015-08-10 20:46 ` tanner at gmx dot net
2020-06-21 17:34 ` xaizek at posteo dot net
2020-11-09 17:45 ` julien.ruffin at ivu dot de
2020-11-30 12:51 ` jruffin at gmail dot com
2022-10-06 12:13 ` [Bug preprocessor/56549] " Dmitriy.Poterukha at uvoteam dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).