[PATCH C++] - SD-6 Implementation Part 1 - __has_include.

Ed Smith-Rowland 3dw4rd@verizon.net
Mon Sep 29 00:10:00 GMT 2014


On 09/25/2014 12:57 PM, Jason Merrill wrote:
> On 09/01/2014 09:34 PM, Ed Smith-Rowland wrote:
>>     (open_file_failed()): Not an error to not find a header file for
>>     __has_include__.
>
> Hmm, looks like this means that __has_include__ will silently return 
> false if a header exists but is unreadable; I would think that we want 
> it to be true (and have an error when the user tries to include it).
>
> Jason
>
I have changed __has_include__ to return true if a header exists but is 
unreadable.  Then I tried to see if an error would occur for a header of 
permission 000.
Just including it gives a permission error.  Putting it into an #if 
block does not.
-------------------------------------------------------
ed@bad-horse:~/tr2$ ls -l hidden.h
---------- 1 ed ed 0 Sep 26 10:27 hidden.h
-------------------------------------------------------
//  Try header that exists but we can't read.
#if __has_include("hidden.h")
#  warning "found hidden.h"
#  include "hidden.h" // No error!
#else
#  error "hidden.h"
#endif

#if 1
#  include "hidden.h" // No error!
#endif
-------------------------------------------------------

Is this a bug in cpp?

I'm going to submit new patches that answer all your questions.  As far 
as this one goes I do no worse than current behavior.
As for [[deprecated]] for C++11 I'll add another patch on top of the four.

Ed



More information about the Gcc-patches mailing list