Gcc

gcc 6 選項“-Wmisleading-indentation”如何可靠工作?

  • July 13, 2020

閱讀GCC 6 Release Series Changes, New Features, and Fixes我發現新選項非常有趣-Wmisleading-indentation

-Wmisleading-indentation warns about places where the indentation of the code
   gives a misleading idea of the block structure of the code to a human reader.
   For example, given CVE-2014-1266:

sslKeyExchange.c: In function 'SSLVerifySignedServerKeyExchange':
sslKeyExchange.c:631:8: warning: statement is indented as if it were guarded by... [-Wmisleading-indentation]
       goto fail;
       ^~~~
sslKeyExchange.c:629:4: note: ...this 'if' clause, but it is not
   if ((err = SSLHashSHA1.update(&hashCtx, &signedParams)) != 0)
   ^~

我只是想知道當它tab space是“未知”時,該選項如何辨識可靠的這些誤導性縮進,gcc因為它可以是 4 或 8 甚至是什麼……

它不能。開發人員明確表示,它基於一組啟發式算法,可以在沒有太多噪音的情況下擷取大多數誤導性縮進。與其他編譯器警告一樣,會有誤報和誤報。讓目前的GCC 在大多數程式碼上鬆散-Wall並哭泣。

引用自:https://unix.stackexchange.com/questions/266737