llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.34k stars 11.7k forks source link

Poisoning Objective-C methods #16303

Open llvmbot opened 11 years ago

llvmbot commented 11 years ago
Bugzilla Link 15931
Version trunk
OS All
Reporter LLVM Bugzilla Contributor
CC @seanm

Extended Description

Summary: Clang inherits the "poison" pragma from GCC. Unfortunately it doesn't support poisoning Objective-C selectors very well.

Steps to reproduce: compile this code.

import <Foundation/Foundation.h>

pragma GCC poison initWithCString:

int main(int argc, char argv[]) { @autoreleasepool { NSString foo = [[NSString alloc] initWithCString:"foo" encoding:NSUTF8StringEncoding]; NSLog(@"%@", foo); } }

Expected results: that should work. I've poisoned "initWithCString:" but used "initWithCString:encoding:".

Actual results: two errors are emitted.

Untitled.m:2:35: error: can only poison identifier tokens

pragma GCC poison initWithCString:

                              ^

Untitled.m:6:37: error: attempt to use a poisoned identifier NSString *foo = [[NSString alloc] initWithCString:"foo" encoding:NSUTF8StringEncoding]; ^ 2 errors generated.

Notes: whether it's a separate pragma or not, I would like to enforce Objective-C code guidelines by poisoning specific selectors. That shouldn't poison other selectors that happen to contain my poisoned selectors in substrings.

seanm commented 11 years ago

+1. There are so many methods Apple doesn't actually mark deprecated in their SDK (or does so only by comment), it would be great to build our own lists.