Skip to content
This repository has been archived by the owner on Nov 2, 2020. It is now read-only.

bad receiver type 'const char *' when compiling ObjC++ #84

Closed
itsthejb opened this issue May 12, 2015 · 4 comments
Closed

bad receiver type 'const char *' when compiling ObjC++ #84

itsthejb opened this issue May 12, 2015 · 4 comments

Comments

@itsthejb
Copy link
Contributor

Hi guys,

So, I'm writing a Tweak for an animation curve in an ObjC++ file (ComponentKit 馃槈), using the dictionary method. It's basically this:

[FBTweakValue(@"a", @"b", @"c",
                  @(UIViewAnimationOptionCurveEaseInOut),
                  (@{
                     @(UIViewAnimationOptionCurveEaseInOut) : @"Ease In-Out",
                     @(UIViewAnimationOptionCurveEaseIn) : @"Ease In",
                     @(UIViewAnimationOptionCurveEaseOut) : @"Ease Out",
                     @(UIViewAnimationOptionCurveLinear) : @"Linear"
                     })) unsignedIntegerValue]

However, this won't compile in an ObjC++ file with the following error:

<redacted>: error: bad receiver type 'const char *'
                FBTweakAnimationCurve(@"foo", @"Bar", @"Cheese");
                ^
In file included from <built-in>:351:
In file included from <command line>:26:
In file included from <redacted>:
<redacted>:18:2: note: expanded from macro 'FBTweakAnimationCurve'
[FBTweakValue(category_, collection_, name_, \
 ^
In file included from <built-in>:351:
In file included from <command line>:26:
In file included from  <redacted>:39:
In file included from  <redacted>:10:
 <redacted>/Headers/Public/Tweaks/FBTweakInline.h:38:58: note: expanded from macro 'FBTweakValue'
#define FBTweakValue(category_, collection_, name_, ...) _FBTweakValue(category_, collection_, name_, __VA_ARGS__)
                                                         ^
In file included from <built-in>:351:
In file included from <command line>:26:
In file included from  <redacted>:39:
In file included from  <redacted>:10:
In file included from  <redacted>/Headers/Public/Tweaks/FBTweakInline.h:10:
 <redacted>/Headers/Public/Tweaks/FBTweakInlineInternal.h:159:127: note: expanded from macro '_FBTweakValue'
#define _FBTweakValue(category_, collection_, name_, ...) _FBTweakDispatch(_FBTweakValueWithoutRange, _FBTweakValueWithRange, _FBTweakValueWithPossible, __VA_ARGS__)(category_, collection_, name_, __VA_ARGS__)
                                                                                                                              ^
 <redacted>/Headers/Public/Tweaks/FBTweakInlineInternal.h:67:174: note: expanded from macro '_FBTweakDispatch'
#define _FBTweakDispatch(__withoutRange, __withRange, __withPossible, ...) __FBTweakConcat(__FBTweakDispatch, __FBTweakIndexCount(__VA_ARGS__))(__withoutRange, __withRange, __withPossible)
                                                                                                                                                                             ^
 <redacted>/Headers/Public/Tweaks/FBTweakInlineInternal.h:65:78: note: expanded from macro '__FBTweakDispatch2'
#define __FBTweakDispatch2(__withoutRange, __withRange, __withPossible, ...) __withPossible
                                                                             ^
 <redacted>/Headers/Public/Tweaks/FBTweakInlineInternal.h:154:87: note: expanded from macro '_FBTweakValueWithPossible'
#define _FBTweakValueWithPossible(category_, collection_, name_, default_, possible_) \
                                                                                      ^
1 error generated.

It's possible to test this by pasting the macro into a plain ObjC file, then changing the type to ObjC++ or renaming to .mm. Since this works, I'm fairly sure this isn't my error...?

Of course, it's possible to work around this by returning the value from a function in an .h/.m helper pair, but raising here in case this is something that could be fixed.

Thanks!

@ashoemaker
Copy link

馃憤

@grp
Copy link
Contributor

grp commented Jul 1, 2015

Sorry, I totally missed this one. I'll take a look as soon as I have time and add a unit test. Or, if you want to send a pull request :)

@itsthejb
Copy link
Contributor Author

Hi there. Had a bit of a chance to look into this today, and appears that this is non-trivial, since FBTweakValue() is actually implemented using _Generic(). However, I notice the inclusion of extern "C" {..., so I'm a bit confused as to whether or not this was expected to work or not.

It seems to me that getting this to work with ObjC++ would require reimplementing FBTweakValue() to use C++ constructs rather than _Generic(). In which case, considering it's possible to just expose Tweaks values from another non-C++ compilation unit, I would say this isn't worthwhile. In which case, perhaps it would be better to just go with:

#ifdef __cplusplus
#error C++ unsupported error, etc... However, you can expose values from blah, blah, blah helpful advice
#endif

...but I'd be interested to know if this was intended to work first.

@itsthejb
Copy link
Contributor Author

I did a quick PR if you think it's ok to just go with the build error "solution".

@grp grp closed this as completed in #88 Jul 15, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants