xcode – -Wformat = 2有什么作用?

前端之家收集整理的这篇文章主要介绍了xcode – -Wformat = 2有什么作用?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_404_2@
我在网上看到了很多关于Clang的-Wformat = 2选项的提及,有时与已知的-Wformat( Xcode列为“Typecheck调用printf / scanf的那个”一起提到,尽管它涵盖了更多的字符串格式API现在).

>这有什么用呢?
>如果确实如此,那么它与-Wformat有什么不同呢?
>两者兼有,或者是另一个的超集是否有用?

解决方法

If it does,what,if anything,does it do differently from -Wformat?

它是从GCC借来的,因为它被设计成适合的替代品. GCC’s description

-Wformat=2

Enable -Wformat plus format checks not included in -Wformat. Currently
equivalent to `-Wformat -Wformat-nonliteral -Wformat-security
-Wformat-y2k’.

这回答了你的大部分问题.

Does this do anything at all?

是.以下程序会发出不同的警告,具体取决于-Wformat = 2的存在(或不存在):

__attribute__((__format__ (__printf__,1,2)))
static void F(const char* const pString,...) {
}

int main(int argc,const char* argv[]) {
    F("",0);
    F(argv[0],0);
    const char str[] = "aaa";
    F(str,0);
    F("%i",0);
    F("%i");
    return 0;
}

注意:看起来Clang roll -Wformat-security为-Wformat.

最后,我没有测试-Wformat-y2k,但它被GCC定义为:

-Wformat-y2k

If -Wformat is specified,also warn about strftime formats which may yield only a two-digit year.

@H_404_2@

猜你在找的Xcode相关文章