2

I have turned on -Wall in my code to get rid of all warnings. Some however I want to allow within the code, so I disable those ones in code. Of the common ones, I can easily find out the warning number in Google and disable them like e.g.:

#pragma warning( disable : 4127 )

But of some, I can't possibly find the corresponding number. For example, I want to disable a:

warning : array subscript is of type 'char' [-Wchar-subscripts]

How do I find its number? Is there a searchable list? The Microsoft documentation isn't searchable on keyword, only on number.

Yellow
  • 3,955
  • 6
  • 45
  • 74
  • 1
    https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warnings-by-compiler-version But your warning and switches do not look like form a Microsoft compiler?! They have a slash like `/Wall`. And the warnings include the number. These look like gcc/clang warnings. – Mihayl Nov 21 '17 at 15:54
  • 3
    The MS compiler tells you the warning number.`warning : array subscript is of type 'char' [-Wchar-subscripts]` is not an output of the MS compiler. – Jabberwocky Nov 21 '17 at 15:54
  • 1
    The MS warnings are like this: _warning __C4700__: uninitialized local variable 'x' used_ – Jabberwocky Nov 21 '17 at 15:56
  • You can disable such warning with: `-Wno-char-subscripts` as a compiler option. And generally replace `-W` with `-Wno-` to disable a specific warning. – OriBS Nov 21 '17 at 16:01
  • Possible duplicate of [Warning: array subscript has type char](https://stackoverflow.com/questions/9972359/warning-array-subscript-has-type-char) – Passer By Nov 21 '17 at 16:09
  • "I have turned on -Wall in my code to get rid of all warnings. " ?? In g++ or clang++ "-Wall" does not disable any warnings, but instead turns on a few (not anywhere near 'all'). More importantly, 'Warnings' are a good thing to enable! To eliminate warnings, you need to a) write correct code, and b) fix your warning generating code. My typical compile has >45 warning-checks enabled, and none explicitly disabled. – 2785528 Nov 22 '17 at 00:15

1 Answers1

7

You are not using a Microsoft compiler, or at least not a Microsoft compiler front end. The warning is printed by the Clang front end. (GCC has a very similar warning, also called -Wchar-subscripts, but the wording of the message is slightly different.)

Clang and GCC do not use numbers for warnings, but names. You can use these pragmata to disable the diagnostic:

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wchar-subscripts"

The code which should be compiled without the warning follows, and with this, you can restore the previous state of the warning (typically enabled):

#pragma GCC diagnostic pop

Note that it says “GCC” because the pragma actually works with GCC and Clang.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92