[cfe-dev] [Clang 3.0] Inconsistent warnings about assignment in a condition

Jon Shier jon at jonshier.com
Fri Mar 16 21:10:50 PDT 2012


I haven't seen anything about a change to the standard init pattern. What is the new one?

Jon Shier

On Mar 16, 2012, at 6:38 PM, Kyle Sluder <kyle at ksluder.com> wrote:

> On Mar 16, 2012, at 1:45 PM, John McCall wrote:
> 
>> On Mar 16, 2012, at 12:44 AM, Alexei Sholik wrote:
>>> I can't find a way to make Clang _always_ trigger warnings about
>>> assignment inside a condition. When I create a new project (Mac or
>>> iOS) in Xcode 4.3.1 and compile it, the following code does not
>>> trigger any warnings:
>>> 
>>> - (id)init
>>> {
>>>  if (self = [super init]) {
>>>      // ...
>>>  }
>>>  return self;
>>> }
>> 
>> We wanted to enable -Wparentheses by default, but we got a lot of pushback
>> over this specific idiom (particularly since Apple puts out example code
>> with this verbatim), so we moved it to a subgroup -Widiomatic-parentheses
>> that is not enabled by default.  If you specifically enable -Wparentheses
>> instead of relying on the default behavior, you should see warnings about
>> this.
> 
> AFAICT Apple's new preferred approach for self-assignment in initializers doesn't use assignment-in-if anymore. So maybe it should be reconsidered?
> 
> --Kyle Sluder
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev





More information about the cfe-dev mailing list