Skip to content

[Clang] User-relevant warnings in system headers #141908

Open
0 of 5 issues completed
Open
0 of 5 issues completed
@cor3ntin

Description

@cor3ntin

We silence warnings in system headers on the basis that such warnings are not user-actionable. In practice, using -Wsystem-headers can be fairly noisy.

https://godbolt.org/z/eaxen4vob

However, we find that this silences... too much.

This boils down to "happens in system headers" not always being a good heuristic for "is user relevant".

The solutions I thought about are

  • Be a lot more aggressive about showing warnings in headers on a case-by-case basis and expect implementers not to trigger any of these warnings.
  • Give implementers a pragma/attribute to show warnings in a region of code - this would be used every time library code could involve a user-provided type/expression
  • In the front end, provides an API to show warnings in system headers based on multiple locations, rather than the location of the warning itself. We would then inspect types and expressions to determine whether they involve user-defined types.
  • Inspect the instantiation stack and show warnings if parts of the stack are in user code
  • When emitting warnings, wait until we have collected all the notes and produce warnings if any of the notes are in user code. This seems particularly involved/inefficient.
  • A new attribute like [[deprecated]] but never silenced

Instantiation stacks make for a not-so-good heuristic:

  • Some warnings in system headers might be relevant even if no instantiation happens
  • Some warnings in system headers might be caused by instantiation from user code and still be completely irrelevant.

A simplification of looking at instantiation stacks is that if a warning is produced in a system header after we have completed the initial parse of that header, we display it.

I suspect we might want to land on a mix of some of these ideas.

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions