Bug 47857 - Pragma once warning when compiling PCH
Summary: Pragma once warning when compiling PCH
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: pch (show other bugs)
Version: 4.4.5
: P3 minor
Target Milestone: 14.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2011-02-23 11:48 UTC by Olaf van der Spek
Modified: 2024-02-11 10:29 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-08-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olaf van der Spek 2011-02-23 11:48:29 UTC
g++ a.h 

a.h:
#pragma once // warning: #pragma once in main file
Comment 1 Andrew Pinski 2011-12-15 02:11:02 UTC
Dup of bug 39029 which shows the warning is just part of the symptom.

*** This bug has been marked as a duplicate of bug 39029 ***
Comment 2 Olaf van der Spek 2011-12-15 10:41:07 UTC
(In reply to comment #1)
> Dup of bug 39029 which shows the warning is just part of the symptom.
> 
> *** This bug has been marked as a duplicate of bug 39029 ***

It's *not* a duplicate. This one is about generating the .gch.
The other one is about using the .gch (and not about the warning message).
Comment 3 Jonathan Wakely 2011-12-15 13:38:25 UTC
If you're going to change the status please check what VERIFIED means (we don't use that status in this bugzilla)
Comment 4 Olaf van der Spek 2012-04-28 14:39:51 UTC
(In reply to comment #3)
> If you're going to change the status please check what VERIFIED means (we don't
> use that status in this bugzilla)

Oops
Comment 5 Joao Matos 2013-10-03 17:42:22 UTC
I can also confirm this bug.

Is there any specific reason why GCC emits the pagma once warning while compiling PCH?
Comment 6 Paul "TBBle" Hampson 2015-01-07 00:25:00 UTC
This looks like a specific instance or duplicate of the much older bug 9471.
Comment 7 Ian Mallett 2017-05-12 07:10:10 UTC
I can also confirm this bug still exists in GCC 7.1.
Comment 8 Romain Geissler 2019-12-03 15:43:42 UTC
Hi,

This is still the case up to gcc 9 (already released) and current trunk of gcc 10.

Cheers,
Romain
Comment 9 Eric Gallager 2023-08-24 08:31:43 UTC
Confirming via bug 89808
Comment 10 GCC Commits 2023-11-14 22:55:12 UTC
The master branch has been updated by Lewis Hyatt <lhyatt@gcc.gnu.org>:

https://gcc.gnu.org/g:9938645fcf914ec2a3fa8137cf1456ad4af5f77c

commit r14-5471-g9938645fcf914ec2a3fa8137cf1456ad4af5f77c
Author: Lewis Hyatt <lhyatt@gmail.com>
Date:   Fri Nov 10 11:10:18 2023 -0500

    c-family: Let libcpp know when the compilation is for a PCH [PR9471]
    
    libcpp will generate diagnostics when it encounters things in the main file
    that only belong in a header file, such as `#pragma once' or `#pragma GCC
    system_header'. But sometimes the main file is a header file that is just
    being compiled separately, e.g. to produce a C++ module or a PCH, in which
    case such diagnostics should be suppressed. libcpp already has an interface
    to request that, so make use of it in the C frontends to prevent libcpp from
    issuing unwanted diagnostics when compiling a PCH.
    
    gcc/c-family/ChangeLog:
    
            PR pch/9471
            PR pch/47857
            * c-opts.cc (c_common_post_options): Set cpp_opts->main_search
            so libcpp knows it is compiling a header file separately.
    
    gcc/testsuite/ChangeLog:
    
            PR pch/9471
            PR pch/47857
            * g++.dg/pch/main-file-warnings.C: New test.
            * g++.dg/pch/main-file-warnings.Hs: New test.
            * gcc.dg/pch/main-file-warnings.c: New test.
            * gcc.dg/pch/main-file-warnings.hs: New test.
Comment 11 Lewis Hyatt 2023-11-14 22:58:43 UTC
Fixed for GCC 14.