Bug 2045069 - cpp stops when finding a missing include
Summary: cpp stops when finding a missing include
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: gcc
Version: 7.9
Hardware: All
OS: Linux
unspecified
medium
Target Milestone: rc
: ---
Assignee: Marek Polacek
QA Contact: Alexandra Petlanová Hájková
URL:
Whiteboard:
Depends On:
Blocks: 2045071
TreeView+ depends on / blocked
 
Reported: 2022-01-25 14:45 UTC by Paulo Andrade
Modified: 2023-07-18 14:16 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 2045071 (view as bug list)
Environment:
Last Closed: 2022-01-25 17:13:53 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-109600 0 None None None 2022-01-25 15:05:12 UTC

Description Paulo Andrade 2022-01-25 14:45:26 UTC
Reproducer:

"""
$ cat test.c
#include <inc1.h>
#include <inc2.h>
#include <inc3.h>
main()
{
}

$ cat inc1.h
#include <limits.h>

$ cat inc2.h
#include <string.h>

$ cat inc3.h
#include <stdio.h>

$ cpp -I. -nostdinc test.c
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "testprogram.c"
# 1 "./inc1.h" 1
In file included from test.c:1:0:
./inc1.h:1:19: fatal error: limits.h: No such file or directory
 #include <limits.h>
                   ^
compilation terminated.
"""

  On rhel6 it did list all missing includes, that is, would print something
like:

"""
# 1 "test.c"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "test.c"
# 1 "./inc1.h" 1
In file included from test.c:1:0:
./inc1.h:1:19: error: limits.h: No such file or directory [enabled by default]
 #include <limits.h>
                   ^
# 2 "test.c" 2
# 1 "./inc2.h" 1
In file included from test.c:2:0:
./inc2.h:1:19: error: string.h: No such file or directory [enabled by default]
 #include <string.h>
                   ^
# 3 "test.c" 2
# 1 "./inc3.h" 1
In file included from test.c:3:0:
./inc3.h:1:18: error: stdio.h: No such file or directory [enabled by default]
 #include <stdio.h>
                  ^
# 4 "testprogram.c" 2

main()
{
}
"""

  It appears the previous behavior should happen if one also pass
-Wno-fatal-errors to cpp command line.

  Note that on rhel7 and newer it prints "fatal error: ...", and on rhel6
it prints "error: ...".

  A possible workaround is to run as:

$ ( export DEPENDENCIES_OUTPUT=1; export SUNPRO_DEPENDENCIES=1; cpp -I. -nostdinc test.c )

what will cause cpp related flags to be set to follow a code path where
it will not cause a fatal error, but print "warning: ..." and list all
missing include files.

  The current behavior is likely the expected, as when not including
a file, any new error/warning messages are likely bogus as it could be
interpreted very differently if the missing include was loaded. But user
relies on previous behavior.

Comment 3 Marek Polacek 2022-01-25 17:13:53 UTC
This was an intentional change to avoid printing too many errors if there's a header missing, as discussed in https://gcc.gnu.org/PR15638.  I'm entirely unwilling to change this in RHEL, sorry.

As a workaround, I suppose you could use
$ DEPENDENCIES_OUTPUT=/dev/null gcc test.c -nostdinc -I. -Werror

Comment 4 Paulo Andrade 2022-01-25 18:23:02 UTC
Thanks for the PR link and reduced workaround that basically provides the same behavior as rhel6.


Note You need to log in before you can comment on or make changes to this bug.