question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compile-time Error: control may reach end of non-void function with Xcode 10.2

See original GitHub issue

TL;DR

Thanks @AidenMontgomery.

  1. Open the source file at ${RN_PROJ}/node_modules/realm/src/jsc/jsc_value.hpp.
  2. Find the switch-case segment at THERE.
  3. Replace the whole switch-case segment with the following code.
    switch (JSValueGetType(ctx, value)) {
        case kJSTypeNull: return "null";
        case kJSTypeNumber: return "number";
        case kJSTypeObject: return "object";
        case kJSTypeString: return "string";
        case kJSTypeBoolean: return "boolean";
        case kJSTypeUndefined: return "undefined";
        case kJSTypeSymbol: return "symbol";
    }

Goals

When I were compiling the React Native Project with Xcode, the compiler prompts an error.

Expected Results

No error.

Actual Results

/Users/***/***/***/node_modules/realm/src/jsc/jsc_value.hpp:54:1: error: control may reach end of non-void function [-Werror,-Wreturn-type]

Version of Realm and Tooling

  • Realm JS SDK Version: 2.25.0
  • React Native: 0.58.6
  • Node: 10.15.2
  • Client OS & Version: iOS 12.2.0

Temp Solution

  1. Open the source code: ${RN_PROJ}/node_modules/realm/src/jsc/jsc_value.hpp;
  2. Add return "null"; between line 33 and 34.

I know this is not a good solution. So I am looking forward to the official solution.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:31
  • Comments:21 (5 by maintainers)

github_iconTop GitHub Comments

48reactions
HengCCcommented, Mar 26, 2019

temp solution :

add default: return "null"; between line 52 and 53,

template<>
inline const char *jsc::Value::typeof(JSContextRef ctx, const JSValueRef &value) {
    switch (JSValueGetType(ctx, value)) {
        case kJSTypeNull: return "null";
        case kJSTypeNumber: return "number";
        case kJSTypeObject: return "object";
        case kJSTypeString: return "string";
        case kJSTypeBoolean: return "boolean";
        case kJSTypeUndefined: return "undefined";
        default: return "null";
    }
    
}

this working for me, waiting for the official solution

40reactions
AidenMontgomerycommented, Mar 26, 2019

From what I can tell, and I’m probably wrong, there is a new entry in the JSType Enum kJSTypeSymbol which is not being handled in the switch statement. Therefore the switch is not handling all of the possible values returned by JSValueGetType

I don’t know what the effect of doing this will be, but I think that the solution is as follows…

inline const char *jsc::Value::typeof(JSContextRef ctx, const JSValueRef &value) {
    switch (JSValueGetType(ctx, value)) {
        case kJSTypeNull: return "null";
        case kJSTypeNumber: return "number";
        case kJSTypeObject: return "object";
        case kJSTypeString: return "string";
        case kJSTypeBoolean: return "boolean";
        case kJSTypeUndefined: return "undefined";
        case kJSTypeSymbol: return "symbol";
    }
}

This does mean that when/if a new value is added to the Enum again we will see the same issue, unless there is a default added, I just don’t know what that should do.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: control may reach end of non-void function in C
You are getting this error because if your for loop breaks due to breaking condition i < n; then it don't find any...
Read more >
[Solved]-Control may reach end of non-void function ERROR
Solution: Try making their (return) type bool and see if it fixes it. Otherwise, consider returning an error value at the end of...
Read more >
How to solve "control may reach end of non void function" error
There are a few ways to fix this. The most direct solution is to add a return statement at the end of the...
Read more >
Xcode 14 Release Notes | Apple Developer Documentation
Workaround: Quit and relaunch Xcode. CGFLOAT_EPSILON is no longer always type Float on watchOS, and it may cause compile issues. (88698530). Workaround: ...
Read more >
C++ Users Guide - Oracle Help Center
Complex Arithmetic Library Functions Default Error Handling 15–7 ... The C++ compiler package consists of a front end, optimizer, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found