Skip to content

Commit

Permalink
compilers: improve a comment describing why we add a silly clang work…
Browse files Browse the repository at this point in the history
…around

Clang is such a great compiler! Not.

Compilers have enhanced diagnostics for some kinds of "well known"
undeclared identifiers, telling you exactly which header you might have
forgotten to include. The reason why clang needs an option GCC doesn't
need is because clang's fixit suggestions, unlike GCC's actually
*changes the type of the error*, as a result of a fixit of all things.

After the fixit suggestion grants this error the right to be ignored,
we start having to add clang-specific options.

Follow-up to #9140

Upstream clang bug, which appears to be going nowhere:
llvm/llvm-project#33905
  • Loading branch information
eli-schwartz committed May 24, 2024
1 parent a66cb97 commit d57ca7d
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions mesonbuild/compilers/mixins/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,23 @@ def get_pch_use_args(self, pch_dir: str, header: str) -> T.List[str]:

def get_compiler_check_args(self, mode: CompileCheckMode) -> T.List[str]:
# Clang is different than GCC, it will return True when a symbol isn't
# defined in a header. Specifically this seems to have something to do
# with functions that may be in a header on some systems, but not all of
# them. `strlcat` specifically with can trigger this.
# defined in a header. Specifically this is caused by a functionality
# both GCC and clang have: for some "well known" functions, arbitrarily
# chosen, they provide fixit suggestions for the header you should try
# including.
#
# - With GCC, this is a note appended to the prexisting diagnostic
# "error: undeclared identifier"
#
# - With clang, the error is converted to a c89'ish implicit function
# declaration instead, which can be disabled with -Wno-error and on
# clang < 16, simply passes compilation by default.
#
# One example of a clang fixit suggestion is for `strlcat`, which
# triggers this.
#
# This was reported in 2017 and promptly fixed. Just kidding!
# https://github.com/llvm/llvm-project/issues/33905
myargs: T.List[str] = ['-Werror=implicit-function-declaration']
if mode is CompileCheckMode.COMPILE:
myargs.extend(['-Werror=unknown-warning-option', '-Werror=unused-command-line-argument'])
Expand Down

0 comments on commit d57ca7d

Please sign in to comment.