Author: dcoughlin Date: Fri May 6 12:51:34 2016 New Revision: 268764 URL: http://llvm.org/viewvc/llvm-project?rev=268764&view=rev Log: [www][analyzer] Add FAQ about suppression of missing localization diagnostic.
Modified: cfe/trunk/www/analyzer/faq.html Modified: cfe/trunk/www/analyzer/faq.html URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/faq.html?rev=268764&r1=268763&r2=268764&view=diff ============================================================================== --- cfe/trunk/www/analyzer/faq.html (original) +++ cfe/trunk/www/analyzer/faq.html Fri May 6 12:51:34 2016 @@ -28,6 +28,7 @@ pointer is never null. How can I tell th null?</a></li> <li><a href="#dead_store">How do I tell the static analyzer that I don't care about a specific dead store?</a></li> <li><a href="#unused_ivar">How do I tell the static analyzer that I don't care about a specific unused instance variable in Objective C?</a></li> + <li><a href="#unlocalized_string">How do I tell the static analyzer that I don't care about a specific unlocalized string?</a></li> <li><a href="#use_assert">The analyzer assumes that a loop body is never entered. How can I tell it that the loop body will be entered at least once?</a></li> <li><a href="#suppress_issue">How can I suppress a specific analyzer warning?</a></li> <li><a href="#exclude_code">How can I selectively exclude code the analyzer examines?</a></li> @@ -78,6 +79,32 @@ You can use the <tt>(void)x;</tt> idiom <pre class="code_example">Instance variable 'commonName' in class 'HappyBird' is never used by the methods in its @implementation</pre> You can add <tt>__attribute__((unused))</tt> to the instance variable declaration to suppress the warning.</p> +<h4 id="unlocalized_string" class="faq">Q: How do I tell the static analyzer that I don't care about a specific unlocalized string?</h4> + +<p>When the analyzer sees that an unlocalized string is passed to a method that will present that string to the user, it is going to produce a message similar to this one: +<pre class="code_example">User-facing text should use localized string macro</pre> + +If your project deliberately uses unlocalized user-facing strings (for example, in a debugging UI that is never shown to customers), you can suppress the analyzer warnings (and document your intent) with a function that just returns its input but is annotated to return a localized string: +<pre class="code_example"> +__attribute__((annotate("returns_localized_nsstring"))) +NSString *LocalizationNotNeeded(NSString *s) { + return s; +} +</pre> + +You can then call this function when creating your debugging UI: +<pre class="code_example"> +[field setStringValue:LocalizationNotNeeded(@"Debug")]; +</pre> + +Some projects may also find it useful to use NSLocalizedString but add "DNL" or "Do Not Localize" to the string contents as a convention: +<pre class="code_example"> +UILabel *testLabel = [[UILabel alloc] init]; +NSString *s = NSLocalizedString(@"Hello <Do Not Localize>", @"For debug purposes"); +[testLabel setText:s]; +</pre> +</p> + <h4 id="use_assert" class="faq">Q: The analyzer assumes that a loop body is never entered. How can I tell it that the loop body will be entered at least once?</h4> <img src="images/example_use_assert.png" alt="example use assert"> _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits