-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RACSignal combineLatest:reduce:] won't compile as Objective-C++ #937
Comments
Can you try changing the declaration of the method to |
That causes another compiler error
|
Right. How about |
Sorry it took me a while to find the old issue where this was done (#630, PR #636). According to the block language specification (http://clang.llvm.org/docs/BlockLanguageSpec.html#block-variable-declarations)
which means the syntax we're using, while supported, is not actually valid. That's probably why it doesn't work with ObjC++. I hope the declaration in my previous reply works, it would suck to have to go back to having |
I'm using ReactiveCocoa as a subproject & target dependency in an iOS project, so it seems to recompile ReactiveCocoa no matter what. I tried compiling RAC unchanged, then removing it from my target dependencies so it would not recompile when I build my project, then changing the header signatures. Xcode insisted on the implementation matching, so I changed the implementations too. (Had to change -reduceEach: and some others as well.) But then it still refuses to compile my code, with the same Would this work better if I was using RAC as a CocoaPod? |
Are you sure it's getting the updated header and not an old one from the build products directory? It should at least give a different error like when you tried with just the Alternatively can you create an empty project with your settings which also exhibits the problem and upload it? |
I did clean the output folder repeatedly, both through Xcode (⌥⇧⌘K) and then through Finder, restarted Xcode a few times... you know, the usual voodoo. Here's a sample project though. Build the ObjCppReduceError target for iPhone Retina 4-inch iOS 7 Simulator. ViewController.m is the Objective-C++ file containing the offending call. In the sample I changed the signature for I tried to modify
I checked that project out on a new machine, and it didn't show the error in ViewController.m at first, but then Xcode did that thing where it adds new errors a few seconds after it finishes the build. Thanks for your help on this. I'd rather use plain Objective-C, but alas I have tons of existing shared cpp code to deal with, so it's tricky. The file in my actual project seems to work ok as an Objective-C file for now, as I haven't started importing any of my usual shared C++ baggage. But I fear this will eventually be a big deterrent to me using ReactiveCocoa unless I rearchitect my whole project. |
Thanks for providing the sample project, it helped me a lot. Turns out the easiest way to deal with this issue is to cast the block to RAC(self.submitButton, enabled) = [RACSignal
combineLatest:@[siteAddressValidSignal, accessKeyValidSignal]
reduce:(id)^id(NSNumber *siteAddressValid, NSNumber *accessKeyValid){
return @(siteAddressValid.boolValue && accessKeyValid.boolValue);
}]; The code compiled without issues once I reverted the changes to RAC and the sample program seems to work fine. |
Sweet! That seems to do the trick in the real project too. Do you think this is a case where clang's Objective-C++ support hasn't yet implemented all the niceties it has for Objective-C, or should that be a question / radar for Apple? Thanks for the help. |
It could be that supporting K&R style unspecified parameters breaks C++ in some way, I'm not familiar enough with C++ to know why that would be the case, but I do know C++ is not a strict superset of C, unlike Objective-C, which means there can be valid C code that isn't valid in C++. As I mentioned before we're abusing of an implementation detail of clang to have nice block types instead of passing Anyway I'm glad this solves the problem. I'll close the issue now but feel free to follow up or open new ones if you encounter any other troubles. Objective-C++ is not very common, so we appreciate any feedback on the subject. |
I don't think this is just an Objective-C++ problem; I experience the same build error. @Coneko's solution of casting to I'm using ReactiveCocoa 2.3, Xcode version 5.1 (5B130a), and my project has "Compiler for C/C++/Objective-C" set to "Default compiler (Apple LLVM 5.1)". Here's the specific version:
Let me know if there's any other information I can provide you with. If you're interested in diagnosing the problem, I can upload a sample project as well. |
Hi @modocache, I'll look at your sample project. |
Thanks, @kastiglione! Here's a minimal repro: https://github.com/modocache/ReactiveBrokeo As you can see, it fails to build on Travis CI as well. |
@modocache I checked that repo, and the problem of your code is So following will be OK: reduceEach:^(NSNumber *yes, NSNumber *no) {
NSLog(@"Am I indecisive? Well, %@ and %@.", yes, no);
return @"foobar"; // The return type would be inferred as `NSString *` (it is compatible with `id`).
} If you'd like to return reduceEach:^id (NSNumber *yes, NSNumber *no) {
NSLog(@"Am I indecisive? Well, %@ and %@.", yes, no);
return nil; // This would be inferred as `void *`, so you have to specify return type as `id`.
} |
@ikesyo You're absolutely right! This pull request demonstrates the fix: https://github.com/modocache/ReactiveBrokeo/pull/2 Thanks for the insight! That resolves my issue, sorry for taking up your time, @kastiglione. |
No problem! 🤘 |
🍰 |
If I have my implementation file type set to "Objective-C++ Source" I get a compiler error like
when attempting to compile something like
If I change the file type to Objective-C, it compiles fine.
The text was updated successfully, but these errors were encountered: