[clang] [clang][Lex] Do not look up files for __has_include in unevaluated operands (PR #247849)

Brad Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 2 12:52:53 PST 2026


brad0 wrote:

> If I'm not mistaken, __has_include should return 1 so that limit won't produce the -1 error; here we skipped the calculation which would have resulted in 0-1.
> 
> Base(without the pr): https://godbolt.org/z/Wx8d3b3G1
> 
> ```shell
> ❯ cat main.cc 
> #if !__has_include(__FILE__)
> #error expected the current source file to be found
> #endif
> 
> #if 0 && __has_embed(__FILE__ limit(__has_include(__FILE__) - 1))
> #endif
> 
> ❯ build/bin/clang main.cc 
> main.cc:5:65: error: invalid value '-1'; must be positive
>     5 | #if 0 && __has_embed(__FILE__ limit(__has_include(__FILE__) - 1))
>       |                                                                 ^
> main.cc:5:65: error: expected value in expression
> 2 errors generated.
> ```

Thanks, good catch. The first token of the limit was lexed before the nested expression reset the flag. EvaluateDirectiveExpression() now treats its whole expression as evaluated, and I added your case to the test.

https://github.com/llvm/llvm-project/pull/247849


More information about the cfe-commits mailing list