0

Been trying to add this flag: -Wshadow=compatible-local (documentation) when compiling but it just keeps throwing this message:


`error: unknown warning option '-Wshadow=compatible-local';
 did you mean '-Wshadow- uncaptured-local'?
 [-Werror,-Wunknown-warning-option]`

Snippet of my makefile:

# COMPILER & FLAGS ============================================================

CC = gcc
CFLAGS = -g -std=c11 -O3 \
         -Wall -Wextra -Werror \
         -Wshadow -Wshadow=compatible-local \
         -Wno-sign-compare \
         -fsanitize=integer \
         -fsanitize=undefined \
         -fsanitize=address -fsanitize-address-use-after-scope

Updated:

Note: my compiler version is clang-900.0.39.2. (It says clang even though you type in gcc, because I'm using macOS and well ... @Aconcagua explains why down below)


Someone know why this is happening ? and/or how to fix it ?

AymenTM
  • 529
  • 2
  • 5
  • 17
  • I believe those are two different flags, in the [documentation](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wshadow_003dcompatible-local) there are different paragraphs for them. So yeah one for `-Wshadow` and a second for `-Wshadow=compatible-local`... if I'm doing it wrong please correct me. – AymenTM Sep 15 '18 at 06:51
  • 4
    What gcc version? Maybe your version is too old to support that flag. – Jesper Juhl Sep 15 '18 at 06:54
  • `Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/usr/include/c++/4.2.1 Apple LLVM version 9.0.0 (clang-900.0.39.2)` – AymenTM Sep 15 '18 at 06:56
  • 9
    That's not gcc. That's clang. – Jesper Juhl Sep 15 '18 at 06:58
  • True lol but... i did `gcc -v` and that's all it gave me. Besides isn't that a version that should run the flag ? Even when using clang as the compiler it gives me that error msg "/ – AymenTM Sep 15 '18 at 06:59
  • 1
    probably a compatibility link/alias – Jean-François Fabre Sep 15 '18 at 07:01
  • Ok @Jean-François Fabre qu'elle est donc la solution ? (i.e So what needs to be done ?) – AymenTM Sep 15 '18 at 07:07
  • 2
    Some time ago, GCC was the default compiler on MacOS, then Apple decided to switch to clang as default. Suppose they linked GCC to clang to avoid people wondering why the compiler disappeared (well, more reasonable: not to break any build systems...). Good idea? At least leading to confusion where incompatibilities come into play... – Aconcagua Sep 15 '18 at 07:41
  • *"How to fix?"* Install a true GCC on your system, replacing the symlink to clang - or go on with clang but drop the flag that apparently is GCC-specific and not supported by clang (or the clang version *you* are using, if clang added the flag later, you could upgrade it). – Aconcagua Sep 15 '18 at 07:47
  • @Aconcagua hey this is actually it, exactly what you said.. and the clang equivalent is actually the flag displayed in the error msg `-Wshadow-uncaptured-local` [documentation](http://clang.llvm.org/docs/DiagnosticsReference.html#wshadow-uncaptured-local) ! Or could also do your suggestion "install a true GCC". – AymenTM Sep 15 '18 at 07:53

2 Answers2

5

It seems that clang uses quite different flag naming: http://clang.llvm.org/docs/DiagnosticsReference.html#wshadow-uncaptured-local

It should be -Wshadow-uncaptured-local rather than -Wshadow=compatible-local.

vpetrigo
  • 325
  • 2
  • 9
2

Some time ago, GCC was the default compiler on MacOS, then Apple decided to switch to clang as default. Suppose they linked GCC to clang to avoid people wondering why the compiler disappeared (well, more reasonable: not to break any build systems...). Good idea? At least leading to confusion where incompatibilities come into play...

"How to fix?"

Install a true GCC on your system, replacing the symlink to clang.

If you prefer going on with clang (not a bad choice either), drop the flag that apparently is GCC-specific and not supported by clang (you can replace it with clang's equivalent, see vpetrigo's answer).

You even might adapt your makefile to be compatible with both: Get the compiler's version string, check if the string returned contains "gcc" or "clang" and then add the appropriate compiler flags conditionally.

Aconcagua
  • 24,880
  • 4
  • 34
  • 59
  • The last paragraph is **not** a good idea. It hard-codes assumptions that will be wrong in a few years if not months. Instead, perform a configure-time (or equivalent) **test** to determine if the compiler supports the warning you want, and only enable it if it's supported. – R.. GitHub STOP HELPING ICE Sep 15 '18 at 16:01