Error No Return Statement In Function Returning Non-void
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might no return in function returning non-void c++ have Meta Discuss the workings and policies of this site About return-statement with no value in function returning 'int' Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting no return in function returning non-void eclipse ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7
No Return Statement In Function Returning Non-void [-wreturn-type]
million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up why is this warning ( no return , in function returning non-void)? up vote 0 down vote favorite void *rastertask() { struct sched_param sparm; memset(&sparm, 0, sizeof(sparm)); sparm.sched_priority = 10; /* 0 = lowest, 99 = highest */ warning 'return' with a value in function returning void sched_setscheduler( 0 /* pid, 0 ==> this process */, SCHED_RR /* policy */, &sparm); unsigned int n_loop; for(n_loop=0;;n_loop++) { struct timespec ts_start, ts_end; clock_gettime(CLOCK_REALTIME, &ts_start); TASK1(Task2ms_Raster); /* gets called every 2ms */ if( (n_loop % 5) == 0) { TASK2(Task10ms_Raster); /* get called every 5 * 2ms = 10ms */ } if( (n_loop % 50) == 0) { TASK3(Task100ms_Raster); /* get called every 50 * 2ms = 100ms */ } if( (n_loop % 250) == 0 ) { /* reset loop counter when smallest common * multiple of timing grid has been reached */ n_loop = 0; } clock_gettime(CLOCK_REALTIME, &ts_end); useconds_t const tasks_execution_time = delta_t_us(&ts_start, &ts_end); if( tasks_execution_time >= MS_to_US(2) ) { /* report an error that tasks took longer than 2ms to execute */ } /* wait for 2ms - task_execution_time so that tasks get called in * a close 2ms timing grid */ else usleep( MS_to_US(2) - tasks_execution_time ); } } int main(int argc, char *argv[]) { pthread_t thread_id if (pthread_create(&thread_
here for a quick overview of the site Help Center Detailed answers to any questions you might have return statement with a value in function returning void Meta Discuss the workings and policies of this site About Us Learn
Non Void Function Should Return A Value Swift
more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us
Warning Control Reaches End Of Non Void Function Wreturn Type
Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like http://stackoverflow.com/questions/23856895/why-is-this-warning-no-return-in-function-returning-non-void you, helping each other. Join them; it only takes a minute: Sign up no return statement in function returning non-void up vote 0 down vote favorite Im new at coding and I get "error:no return statement in function returning non-void" for this code: template
| Forgot Password Login: [x] User account creation filtered due to spam. Bug43943 - "warning: no return statement in function returning non-void" should be an error Summary: "warning: no return statement in function returning https://gcc.gnu.org/bugzilla/show_bug.cgi?id=43943 non-void" should be an error Status: RESOLVED WORKSFORME Alias: None Product: gcc Classification: Unclassified Component: https://issues.asterisk.org/jira/browse/PRI-143 c++ (show other bugs) Version: unknown Importance: P3 enhancement Target Milestone: --- Assignee: Not yet assigned to anyone URL: Keywords: Depends on: Blocks: Reported: 2010-04-29 20:12 UTC by David Rothlisberger Modified: 2010-04-30 14:01 UTC (History) CC List: 1 user (show) gcc-bugs See Also: Host: Target: Build: Known to work: Known to fail: Last reconfirmed: Attachments Add an attachment in function (proposed patch, testcase, etc.) Note You need to log in before you can comment on or make changes to this bug. Description David Rothlisberger 2010-04-29 20:12:55 UTC I know that dozens of bugs have been opened for this over the years, but please read this through. If you have a C++ program missing a return statement from a function that is supposed to return a value, g++ will compile it happily with no errors in function returning (or even a warning, unless -Wreturn-type or -Wall is used). Trying to use the return value from the function will most likely cause a segmentation fault. Dozens of bugs have been opened for this over the years (e.g. bug 11474), all rejected as invalid based on the following statement from section 6.6.3 of the C++ standard: Flowing off the end of a function is equivalent to a return with no value; this results in undefined behavior in a value-returning function. However, the very same paragraph begins with: A return statement without an expression can be used only in functions that do not return a value, that is, a function with the return type void, a constructor (12.1), or a destructor (12.4). In my opinion, the standard contradicts itself. Either flowing off the end of a function is "equivalent to a return with no value" (i.e. invalid according to the beginning of the paragraph) or it is "undefined behaviour". It can't be both. Appendix C is informative rather than normative, but can help us understand the intent of the standard. Section C.1.4 says: Change: It is now invalid to return (explicitly or implicitly) from a function which is declared to return a value without actually returning a value. Rationale: The caller and callee may assume fairly elaborate return-value mechanisms for the
statement in function returning non-void" compile error.Agile BoardCanned Response ExportJSONXMLWordPrintable Details Type: Bug Status: Closed Severity: Blocker Resolution: Fixed Affects Version/s: None Target Release Version/s: None Component/s: General Labels: None Environment: Ubuntu 12.04.1 LTS, gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 Frequency of Occurrence: Constant Regression: No Description This appears to be an old condition that is caught by newer compilers. With gcc 4.6.3 it's possible to get the following error: $ make gcc -Wall -Werror -Wstrict-prototypes -Wmissing-prototypes -g -fPIC -O2 -MD -MT pridump.o -MF .pridump.o.d -MP -c -o pridump.o prid~ pridump.c: In function 'pri_bridge': pridump.c:117:1: error: no return statement in function returning non-void [-Werror=return-type] cc1: all warnings being treated as errors make: *** [pridump.o] Error 1 Changing the function return value to void fixes the issue since there were no places in the code that used the return value. Reported by: Birger "WIMPy" Harzenetter OptionsSort By NameSort By DateAscendingDescendingDownload AllAttachments 0001-Fix-no-return-statement-in-function-returning-non-vo.patch 07/Sep/12 11:39 PM 1 kB Shaun Ruffell Activity Ascending order - Click to sort in descending order All Comments Work Log History Activity CI Builds Transitions Gerrit Reviews Source Reviews Builds Hide Permalink Shaun Ruffell added a comment - 07/Sep/12 11:39 PM Attached 0001-Fix-no-return-statement-in-function-returning-non-vo.patch which is a trivial fix. Show Shaun Ruffell added a comment - 07/Sep/12 11:39 PM Attached 0001-Fix-no-return-statement-in-function-returning-non-vo.patch which is a trivial fix. Hide Permalink Shaun Ruffell added a comment - 07/Sep/12 11:47 PM - edited A note on how to use git to apply this patch quickly to the 1.4 branch of libpri. If you have git and subversion installed on your workstation, you can cut and paste the following commands into a console window which will do all the work of getting the patch in a local repo ready to commit