IOS Xcode Enable/disable Clang Warnings

Source: Internet
Author: User

Original blog. Reprint please indicate the source
Blog.csdn.net/hello_hwc
Welcome to the specific explanations column for my iOS SDK, which has a lot of basic articles.
Http://blog.csdn.net/column/details/huangwenchen-ios-sdk.html

Preface: Warnings is a very important part of coding, the compiler gives reasonable warning to help developers find their own code problems, to prevent a lot of bugs.
By default, you create a project with Xcode that will proactively open some important warnings. But many other times, we need a more complete reminder of the compiler.

iOS development adopts the clang compiler.

The default warning can be found in the build settings.

Searching for warnings in search, you can see that this is the warnings for all languages

Of course. can also open warning for different languages, also in build settings

But. Such a turn-off customization is very good. Sometimes we just need to open up all or open all the important warnings.
At this time, enter

Ability to add some build flags to enable warnings. The basic one is three.

1. -Wall Clang feel that he can accurately report the warning
2. -Wextra extra harsh warnings. These warnings do not necessarily cause errors. For example, assuming that the flag is used, assigning singned to unsigned triggers a warning, and most of the time it is fine to assign a value.


3. -Weverything All warnings

General items are open -Wall and -Wextra two warnings to ensure there are no serious errors. Of course. Let's say there's something obvious that doesn't go wrong. Ability to close some or some warnings.

-Wall-Wno-unused-variable//启用Wall可是剔除unused-variable
Force a warning to be turned on or off with a statement

Force a warning to open

#warning "This method can not be used"

Force an error to open

#error "You must add this key,or you will fail"

Force a warning to close
Like what
There's a warning here. Test this selector is not implemented

[selfperformSelector:@selectorwithObject:nil];

Force this warning off

#pragma clang diagnostic push#pragma clang diagnostic ignored "-Wundeclared-selector"    [self performSelector:@selector(test) withObject:nil];#pragma clang diagnostic pop
Frequent use of clang Warning
  • Wall
  • Wbad-function-cast
  • Wcast-align
  • Wconversion
  • Wdeclaration-after-statement
  • Wdeprecated-implementations
  • Wextra
  • Wfloat-equal
  • wformat=2
  • Wformat-nonliteral
  • Wfour-char-constants
  • Wimplicit-atomic-properties
  • Wmissing-braces
  • Wmissing-declarations
  • Wmissing-field-initializers
  • Wmissing-format-attribute
  • Wmissing-noreturn
  • Wmissing-prototypes
  • Wnested-externs
  • Wnewline-eof
  • Wold-style-definition
  • Woverlength-strings
  • Wparentheses
  • Wpointer-arith
  • Wredundant-decls
  • Wreturn-type
  • Wsequence-point
  • Wshadow
  • Wshorten-64-to-32
  • Wsign-compare
  • Wsign-conversion
  • Wstrict-prototypes
  • Wstrict-selector-match
  • Wswitch
  • Wswitch-default
  • Wswitch-enum
  • Wundeclared-selector
  • Wuninitialized
  • Wunknown-pragmas
  • Wunreachable-code
  • Wunused-function
  • Wunused-label
  • Wunused-parameter
  • Wunused-value
  • Wunused-variable
  • Wwrite-strings
Difficult mode

The so-called difficult mode is to turn on all warnings. and take warnings as error. This means that the program will not compile and execute only if another warning is present.

References link
http://onevcat.com/2013/05/talk-about-warning/
Http://programmers.stackexchange.com/questions/122608/clang-warning-flags-for-objective-c-development
Http://amattn.com/p/better_apps_clang_weverything_or_wall_is_a_lie.html
http://nshipster.cn/clang-diagnostics/

IOS Xcode Enable/disable Clang Warnings

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.