Bug 82695 - gnu gcc (4.8 - 7.1) cannot parse some system headers in macOS (10.12)
Summary: gnu gcc (4.8 - 7.1) cannot parse some system headers in macOS (10.12)
Status: RESOLVED DUPLICATE of bug 69960
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.8.5
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-24 09:22 UTC by Ev Drikos
Modified: 2018-05-02 18:05 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ev Drikos 2017-10-24 09:22:33 UTC
Hi,

gnu gcc cannot parse some system headers in macOS (10.12)
. One bug is this:

$ cat framework-1.c
#include <Carbon/Carbon.h>
int main(){
 return 0;
}
$ gcc framework-1.c
In file included from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGContext.h:18:0,
                 from /System/Library/Frameworks/CoreGraphics.framework/Headers/CGBitmapContext.h:9,
                 from /System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h:11,
                 from /System/Library/Frameworks/ApplicationServices.framework/Headers/ApplicationServices.h:35,
                 from /System/Library/Frameworks/Carbon.framework/Headers/Carbon.h:24,
                 from framework-1.c:1:
/System/Library/Frameworks/CoreGraphics.framework/Headers/CGFont.h:53:1: error:initializer element is not constant
 static const CGFontIndex kCGGlyphMax = kCGFontIndexMax;


The error is issued in gcc/c/c-typeck.c by the following fragment (7 lines):
      else if (require_constant
	       && !initializer_constant_valid_p (inside_init,
						 TREE_TYPE (inside_init)))
	{
	  error_init ("initializer element is not constant");
	  inside_init = error_mark_node;
	}

Is there a workaround that would allow gcc to accept such an initialisation? 


Ev. Drikos
Comment 1 Marek Polacek 2017-10-24 09:39:09 UTC
I think this is a valid request (though not a bug), as discussed in the other BZ.

You can use e.g. enums to statically initialize variables.

*** This bug has been marked as a duplicate of bug 69960 ***
Comment 2 Ev Drikos 2017-12-01 11:45:52 UTC
The patch in PR/69960 indeed solves the problem described in PR/69960.

I'll wait until next gcc release to see if it also solves the problem described in this PR.

Thanks,
Ev. Drikos
Comment 3 Ev Drikos 2018-05-02 18:05:05 UTC
gcc 8.1 on macos 10.13.4 successfully passes this test.

Thanks,
Ev. Drikos