yaxunl added a comment.

In D84364#2168036 <https://reviews.llvm.org/D84364#2168036>, @tra wrote:

> One side effect of this change is that we'll probably stop producing 
> diagnostics for the code that is known to be wrong, but happens to be unused.
>
> E.g.
>
>   __host__ __device__ static void hd() {
>      no_such_type_t t;
>   }
>
>
> We obviously can never compile this function on either side of the 
> compilation and clang currently does diagnose it on both sides.
>  However, if all diagnostics in HD functions are postponed until codegen, 
> this error will go unreported.
>
> What if I have a syntax error in a HD function? I'd still want it to be 
> diagnosed. 
>  It's going to be interesting to see how it affects parsing subsequent code. 
>  E.g https://godbolt.org/z/1vfPcc -- clang complains about the error in 
> `innocent` due to an error in `hd`. If all diags issues in `hd` are postponed 
> and the user only sees `error: function definition is not allowed here`, it 
> will be rather confusing, because the `innocent` itself is perfectly fine.


A diagnostic will be deferred only if clang successfully parsed a function 
declaration and the current context is a function declaration.

In the above situation, clang fails to parse the function and the current 
context is not a function, therefore the error is emitted immediately, like 
before.

I have added a lit test for such situation.

> Also, this patch may need more eyes on it. I'm sure there are more corner 
> cases we may need to think about. 
>  E.g. how would it affect SFINAE? Will it allow some things to succeed where 
> they would've failed previously? If so, is it always the right thing to do?

We only defer diagnostics happen inside a host device function. My guess is 
that SFINAE will work as before since it happens not in a function scope, 
therefore it is not deferred. I will add some tests.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D84364/new/

https://reviews.llvm.org/D84364



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to