Quuxplusone added a comment.

> Hmm... I like prior art. That clangd supports it suggests that there's a 
> section of code I can look at for inspiration if we were to replace this 
> pragma with the IWYU comment-pragma (I wonder why they didn't just go with 
> `#pragma IWYU ...`?). Is it reasonable for a compiler to interpret comments 
> and issue/adjust diagnostics based on those comments? I thought that was the 
> purpose of a //pp-pragma//.

I can answer that one! Pragmas tend to be for things with real in-game effects 
that require compiler support, such as `#pragma once` or `#pragma thumb`. If a 
TU contains a line of the form `#pragma ...` that the current compiler doesn't 
recognize, that's usually a bug. Compiler vendors reflect that fact by 
providing `-Wunknown-pragmas` (and turning it on pretty aggressively). 
https://stackoverflow.com/questions/132667/how-to-disable-pragma-warnings

For things that "don't really matter" — such as (1) source encoding, (2) switch 
case fallthroughs, (3) IWYU relationships — it's usually easier to just do a 
special kind of comment, rather than forcing all your users to worry about 
`-Wunknown-pragmas` warnings on older or third-party compilers. All compilers 
silently ignore "unknown comments," which is exactly what we want for these 
kinds of things. OTOH, special comments are hard to hide behind macros, whereas 
`[[attributes]]` and `_Pragma("s")` are easier.

If IWYU has already developed a de facto standard for this information, I would 
recommend libc++ just use it (perhaps with no changes needed in clang at all). 
This would have the benefit of getting libc++ to work with IWYU out-of-the-box, 
instead of having to go beg IWYU to implement support for a new `#pragma 
include_instead`.  Is any IWYU developer aware of D106394 
<https://reviews.llvm.org/D106394> yet? You should definitely try to get them 
involved here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D106394

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

Reply via email to