warning non void function does not return a value

It is likely that a wrong variable is being incremented inside the 'for' operator. It only takes a minute to sign up. V2620. V1005. V676. V3063. V540. V814. V775. Unsafe double-checked locking. V807. Do not warn if a caller of a function marked with attribute warn_unused_result (see Variable Attributes) does not use its return value. Perhaps, this is a typo and 'X' variable should be used instead of 'Y'. Exceptions raised inside noexcept functions must be wrapped in a try..catch block. OWASP. V3169. V651. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. A void function will automatically return to the caller at the end of the function. V2599. V3503. Inspect the following programs and state what they output, or whether they will not compile. It is possible that 'else' block was forgotten or commented out, thus altering the program's operation logics. OWASP. V538. Suspicious type conversion: HRESULT -> BOOL (BOOL -> HRESULT). Perhaps, 'ThenBy' should be used instead. Generating points along line with specifying the origin of point generation in QGIS. The expression is always true/false. There should be no implicit integral-floating conversion. V626. V3128. nlohmann/json.hpp:20017:5: warning: non-void function does not return a value in all control paths [-Wreturn-type], reference operator[](T* key) This will result in undefined behavior. Code contains invisible characters that may alter its logic. Possibly meant: 'A -= B'. Bit fields should only be declared with explicitly signed or unsigned integer type. Consider using the M_NN constant from . Calling a virtual (overridden) event may lead to unpredictable behavior. Classes that define 'equals' method must also define 'hashCode' method. Consider reviewing 'X'. The default is -Wunused-result. Octal constants should not be used. V2502. V2517. V3005. V695. error: non-void function does not return a value in all control paths [-Werror,-Wreturn-type]} bool is_full() { if() { return 1; } else if() { return 0; } else if() { return 1; } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 : V3521. V3103. Getting "non-void function does not return a value in all control paths", New blog post from our CEO Prashanth: Community is the future of AI, Improving the copy in the close modal and post notices - 2023 edition, Embedded hyperlinks in a thesis or research paper. V3188. Function is not declared. Use volatile variable(s) or synchronization primitives to avoid this. malloc() function accepts a dangerous expression in the capacity of an argument. Consider checking the N format items of the 'Foo' function. Cyclomatic complexity: NN. Argument of the '|' bitwise operation always contains non-zero value. ** By clicking this button you agree to our, * By clicking this button you agree to our, Free PVS-Studio license for Microsoft MVP specialists, To get the licence for your open-source project, please fill out this form. Consider inspecting usage of 'Y' counter. It can result in an overflow. You are assuming that loop will always run, but, what if an empty string ends up getting submitted? V6080. V3161. An exception handling block does not contain any code. Pointer was used unsafely after its check for nullptr. To learn more, see our tips on writing great answers. Inconsistent synchronization of a field. Two or more case-branches perform the same actions. My advice would be to create a new option Wreturn-pedantic. V3069. MISRA. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. V808. The function with the 'abort/exit/getenv/system' name should not be used. Use of uninitialized variable 'Foo'. The memory areas must not overlap. Boundary between numeric escape sequence and string is unclear. This can result in confusion. V3018. V707. A pattern was detected: A || (A && ). V2612. The report_square function has a void return type, so it doesn't have an expression in its return statement. Unsigned right shift assignment of negative 'byte' / 'short' value. Every switch-clause should be terminated by an unconditional 'break' or 'throw' statement. Unions should not be used. It is suspicious that value 'X' is assigned to the variable 'Y' of HRESULT type. Interpreting non-statistically significant results: Do we have "no evidence" or "insufficient evidence" to reject the null? Function receives an odd argument. V2504. AUTOSAR. Expression contains a suspicious mix of integer and real types. V821. V5303. The 'value' parameter is rewritten inside a property setter, and is not used after that. Functions are not required to return a value back to the caller. Modification of variable is unsequenced relative to another operation on the same variable. The function with the 'abort/exit/getenv/system' name should not be used. Browse other questions tagged, Where developers & technologists share private knowledge with coworkers, Reach developers & technologists worldwide, FWIW, compiling the example code on godbolt.org with, @EricPostpischil but compiler does not know if, Yes, it does know. The loop will not be executed. Suspicious access to element by a constant index inside a loop. OWASP. It is suspicious that the argument of sizeof() operator is the expression. V1011. Exception was thrown by pointer. Suspicious assignment inside the conditional expression of 'if/while/for' statement. AUTOSAR. V5613. V694. Probably meant: *ptr = zero. V505. An argument containing a file path could be mixed up with another argument. MISRA. Consider assigning value to 'foo' variable instead of declaring it anew. V2590. One pair of parentheses is unnecessary or misprint is present. The compiler makes no such assumptions, so you need to make sure that there is a return path that will be followed if the return statement inside your loop is never reached. Consider checking for typos. Call of 'std::is_constant_evaluated' function always returns the same value. V3107. Calling the 'SingleOrDefault' method may lead to 'InvalidOperationException'. V6035. Comparing objects of incompatible types. V2540. It is possible that a typo is present inside the expression. V109. An exception handling block does not contain any code. V1041. V712. AUTOSAR. It is suspicious that it is used as a variable of a Boolean-type. Check lines: N1, N2. Early returns can be used in value-returning functions too: First, print() is called. The expression is excessive or contains a logical error. Object was created but not used. nlohmann/json.hpp:20925:5: warning: non-void function does not return a value in all control paths [-Wreturn-type], const_reference operator[](const typename object_t::key_type& key) const V3165. V3114. Code formatting implies that the statement should not be a part of the 'then' branch that belongs to the preceding 'if' statement. The object was used after it was verified against null. Pseudo random sequence is the same at every program run. Void functions are created and used just like value-returning functions except they do not return a value after the function executes. Consider checking for typos. The reason for the error/warning message is because a void function, by definition, does not return a value. Classes should always be derived from std::exception (and alike) as 'public'. V829. The outer type contains static field/property with identical name. An identifier with array type passed as a function argument should not decay to a pointer. Possible overflow. What happens to the returned value, if one is specified, depends on the implementation. (This const / volatile distinction is not important.) Consider replacing standard container with a different one. Unity Engine. Consider using 'i + 1' instead. V705. Make sure the expression is correct. V753. Calling method or accessing property of potentially disposed object may result in exception. There are identical sub-expressions to the left and to the right of the 'foo' operator. There should be no attempt to write to a stream that has been opened for reading. The value is out of range of enum values. Consider inspecting the expression. V014. Function always returns the same value of NN. Is the code I've written here adequate to do that? The return expression is forced to use a floating-point operation by casting one of the operands to double. A function with a non-void return type must return an answer no matter what its parameters are. Object may be created in-place in a container. Is it safe to publish research papers in cooperation with Russian academics? V2552. The function with the 'qsort/bsearch' name should not be used. The passing of data to or from this function may be affected. Why are players required to record the moves in World Championship Classical games? The functions from time.h/ctime should not be used. Possibly, an override was intended. V2543. V794. The 'sizeof' expression returns the size of the container type, not the number of elements. Hi, been using 2.0.1 so far over the proposed workaround (void function instead of non-void function). V3073. What's the cheapest way to buy out a sibling's share of our parents house if I have no cash and want to pay less than the appraised value? V532. V796. Decreased performance. V6014. NullReferenceException is possible. If you would like to change your settings or withdraw consent at any time, the link to do so is in our privacy policy accessible from our home page.. V600. Values of different enum types are compared. You may or may not use the return . MISRA. Expression is enclosed by parentheses twice: ((expression)). The macro with the 'setjmp' name and the function with the 'longjmp' name should not be used. The first 'if' statement contains method return. V749. The '||' operator is surrounded by opposite expressions 'x' and '!x'. It can possibly be replaced by the call to the 'find' function. Unreachable code under a 'case' label. Single-line comments should not end with a continuation token. When a return statement contains an expression in functions that have a void return type, the compiler generates a warning, and the expression isn't evaluated. V611. rev2023.4.21.43403. V833. Implicit type conversion from memsize to double type or vice versa. Sign in to comment MISRA. Connect and share knowledge within a single location that is structured and easy to search. There should be no user-defined variadic functions. Why do we ask to use Business As soon as your program hits that, it will stop executing the loop and return to the main function, performing only a single iteration of the loop. Some types of expressions require values. The return value of non-void function should be used. The report_square function calls square with a parameter value of INT_MAX, the largest signed integer value that fits in an int. Abnormality within similar comparisons. V3530. The 'SuspendThread' function is usually used when developing a debugger. Identifiers declared in the same scope and name space should be distinct. The 'switch' statement should have 'default' as the last label. Expression resulting from the macro expansion should be surrounded by parentheses. Usage of non memsize type for pointer arithmetic. OWASP. V700. Suspicious string consisting of two parts is used for initialization. V513. V622. Do not define an unnamed namespace in a header file. V3508. MISRA. Consider inspecting the 'for' operator. V719. Use memsize-type here. Consider reviewing 'X'. Parameter is always rewritten in function body before being used. Non-void functions are required to have a return type. V3061. Pointer was used in the logical expression before its check for nullptr in the same logical expression. This is unexpected behavior. NullReferenceException is possible. Possible ReDoS vulnerability. V3068. But, do are you sure you want your return statement inside your loop to begin with? and '.' Already have an account? Asking for help, clarification, or responding to other answers. Consider checking the first actual argument of the 'Foo' function. V3148. The 'Foo' function is called twice in the specified expression to calculate length of the same string. The '<' operator should probably be replaced with '<<'. The variable is assigned but is not used by the end of the function. It is suspicious that the result of the statement is a part of the condition. This pattern is suspicious. The '#pragma warning(push/pop)' should be used instead. Explicit conversion from 'void *' to 'int *'. At the end of printHi, control returns to main and the program proceeds. Microsoft-specific: The Microsoft C implementation returns the expression value to the process that invoked the program, such as cmd.exe. V3084. Consider using parentheses in the expression. privacy statement. MISRA. Probably the '+=' should be used here. V555. V3158. If control passes to Exit Function or End Function and you have not assigned any value to the procedure name, the procedure returns the default value of the return data type. See N argument of function 'foo' in derived class 'derived' and base class 'base'. Already on GitHub? It is possible that 'i < X.size()' should be used instead of 'X.size()'. Unreachable code should not be present in the project. V3009. Significant bits may be lost. A value-returning function should include a return statement, containing an expression. Unexpected uint64 behaviour 0xFFFF'FFFF'FFFF'FFFF - 1 = 0? Two or more case-branches perform the same actions. Why does Acts not mention the deaths of Peter and Paul? Consider using: static_cast/const_cast/reinterpret_cast. The 'if (ptr != NULL)' check can be removed. WPF: the type registered for DependencyProperty does not correspond with the type of the property used to access it. V535. The operation is executed 2 or more times in succession. Functions of strcmp() kind can return any values, not only -1, 0, or 1. Any label should be declared in the same block as 'goto' statement or in any block enclosing it. the first printHi() in the above example), were calling a function for its behavior, not its return value. Then main returns a value of 0 (typically used to report success) to end the program. The functions from time.h/ctime should not be used. It causes the function to return to the caller immediately. OWASP. The 'Foo' function is called twice to deallocate the same resource. For example: In the above program, the value to be printed needs to be provided on the right-side of the std::cout <<. V6086. Example of safe code: printf("%s", str); V619. V2525. Temporary object is created and then destroyed. V630. Consider making the project fully compilable and building it before analysis. The 'restrict' specifier should not be used. V732. Possible use of left shift operator instead of comparison operator. One of the operands in the operation equals NN. MISRA. V633. The compiler may issue a warning diagnostic message about unreachable code if it finds any statements placed after the return statement. V692. The 'X' counter is not used inside a nested loop. V2541. Potentially tainted data is processed by regular expression that contains an unsafe pattern. This leads to undefined behavior. V803. For more information on hiding warnings or treating warnings as errors, see Configuring Warnings in Visual Basic. V520. Usage of a suspicious mutex wrapper. Your function should return a vector in every possible condition. V3011. Possibly an equality comparison was intended. Unreachable code detected. The alignment rules and type sizes have been changed. V011. V5610. It is possible that macro expansion resulted in incorrect evaluation order. V1043. I did return true and false but its still giving me this error [deleted] 2 yr. ago More posts you may like V6031. Consider naming the object. V6044. Non-void functions always have to have a return statement. The operator evaluates both operands. The best answers are voted up and rise to the top, Not the answer you're looking for? V3537. What were the poems other than those by Donne in the Melford Hall manuscript? By default, this message is a warning. V006. This may lead to undefined behavior. V2506. Function exited without performing epilogue actions. It is possible that 'foo = bar == baz ? AUTOSAR. It's probably an error or un-optimized code. Check if program logic handles it correctly. V3014. V773. This may be a potential error. This value is already assigned to the 'b' variable. The 'throw' keyword could be missing. V2581. V2579. Memory allocation will lead to an exception. Consider casting operands, not the result. V2606. Moving an object in a return statement prevents copy elision. Perhaps the '??' Bool type value is compared with value of N. Consider inspecting the expression. It is not recommended to return null or throw exceptions from 'toString' / 'clone' methods. MISRA. V592. Priority of '+' operation is higher than priority of '<<' operation. V5011. V5628. Controlling expressions should not be invariant. Understanding the probability of measurement w.r.t. Possible typo in the spelling of a pre-defined macro name. OWASP. V689. Consider restricting the type parameter to reference types. V580. If you haven't received our response, please do the following: check your Spam/Junk folder and click the V6097. V635. V660. If no return statement appears in a function definition, control automatically returns to the calling function after the last statement of the called function is executed. Consider inspecting the first parameter of 'getline' function. Likewise, report_ratio returns void, so we don't save its return value, either. Thanks for contributing an answer to Stack Overflow! Let's consider an example: V787. V3136. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. The 'throw' keyword could be missing. V6081. The address of an object with local scope should not be passed out of its scope. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. V703. Consider making it implement 'IDisposable' interface. This can result in an overflow. V3059. Consider replacing methods: 'insert' -> 'emplace', 'push_*' -> 'emplace_*'. The 'switch' statement should have 'default' as the last label. Why don't we use the 7805 for car phone chargers? It is not recommended to return null or throw exceptions from 'ToString()' method. V514. Call of function 'foo' with variable number of arguments. Expression of the 'A =- B' kind is used. Consider inspecting the loop expression. The first 'if' statement contains function return. V6023. Potentially unsafe double-checked locking. the platforms: Continuous use of the analyzer in software development, Deploying the analyzer in cloud Continuous Integration services, Additional configuration and resolving issues. ps: thanks for the awesome library. The comma operator should not be used. Potentially tainted data is used in the XPath expression. Use _beginthreadex/_endthreadex functions instead of CreateThread/ExitThread functions. Explicit conversion from memsize type to 32-bit integer type. Consider creating a pointer/reference to avoid using the same expression repeatedly. Variables are initialized through the call to the same function. AUTOSAR. V659. Consider reviewing the correctness of 'X' item's usage. Serialization order of fields should be preserved during deserialization. Variable is not used after memory is allocated for it. In this case, we can call either a non-value returning function, or we can call a value-returning function and just ignore the return value. The variable was utilized in the logical expression before it was verified against null in the same logical expression. Passing objects of incompatible types to the method of collection. Expressions that use comma operator ',' are dangerous. (This const / volatile distinction is not important.) Assigning potentially negative or large value as timeout of HTTP session can lead to excessive session expiration time. If function ends without return (or throw), then the behaviour of the program will be undefined. Floating-point values should not be tested for equality or inequality. Flowing off the end of thesefunctions is equivalent to a'return 0;'. Condition of a loop is always true/false. V6002. Member operator[] of 'foo' class has a 32-bit type argument. MISRA. The second function call to function printHi() wont even compile. AUTOSAR. V727. Custom declaration of standard type. V3140. Consider inspecting the NNth argument of the 'Foo' function. Incorrect index type: 'foo[not a memsize-type]'. Functions should be declared in prototype form with named parameters. V2566. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. OWASP. 565), Improving the copy in the close modal and post notices - 2023 edition, New blog post from our CEO Prashanth: Community is the future of AI. It's possible that the line was commented out improperly, thus altering the program's operation logics. V2505. V644. V704. Number of iterations in loop equals size of a pointer. Value of the essential character type should be used appropriately in the addition/subtraction operations. V2554. V6052. The standard input/output functions should not be used. return reverseString return Check the shift operator. V711. V3020. The same sub-expression is present on both sides of the operator. AUTOSAR. If a function sometimes forgets to return a result, you will get a warning (if you have requested warnings). V3540. V2587. Type casting is used 2 times in a row. control reaches end of non-void functions -wreturn-type. Undefined behavior will occur in case of signed integer overflow. Use memsize type instead. Parameter 'A' is always rewritten in method body before being used. V3551. V2594. V3016. V3160. V1071. To view the purposes they believe they have legitimate interest for, or to object to this data processing use the vendor list link below. V3134. Incorrect format. He also rips off an arm to use as a sword. Pointer to FILE should not be dereferenced. It is possible that different variables are used inside initializer and iterator. All conditional inclusion preprocessor directives should reside in the same file as the conditional inclusion directive to which they are related. V668. The expression is excessive or contains a misprint. V3516. The left operand of integer division is less than the right one. V812. Connect and share knowledge within a single location that is structured and easy to search. V1047. V6041. V2524. Passing the value into the 'Foo' method will result in an exception. V120. Suspicious pointer arithmetic. V830. V5624. Consider inspecting the loop expression. V2545. Potential logical error. V3060. Allocation of memory by the pattern "(X*)malloc(sizeof(Y))" where the sizes of X and Y types are not equal. V2012. V824. MISRA. Currently your code is returning the vector based on conditions. V1075. An identifier declared in an inner scope should not hide an identifier in an outer scope. Comma operator ',' in array index expression. It is inefficient to identify an empty string by using 'strlen(str) > 0' construct. operator should have 'bool' type. V3535. V5009. V1053. Decreased performance. V2559. V605. V6038. So GCC knows there is no possible control path that does not return a value, but it reported the warning (elevated to an error) anyway. Empirical analysis. V3026. Does a password policy with a restriction of repeated characters increase security? Variable should be declared in a scope that minimizes its visibility. Identical expression to the left and to the right of compound assignment. Decreased performance. Compound assignment expression 'X += X + N' is suspicious. Consider inspecting this expression. A minor scale definition: am I missing something? Potentially tainted data is used to create query. There is an easy solution to the problem, even if we understand that every condition is covered we should add a return statement at the end of the function so the compiler is sure that the non-void function will be returning some value. A switch-expression should not have Boolean type. AUTOSAR. V6061. A function name may be missing. Possible incorrect order of arguments passed to method. V3167. V3546. Maximum size of a vector is known at compile time. An identifier with array type passed as a function argument should not decay to a pointer. An object is used as an argument to its own method. Here is my code: why does it show compile error?? Use volatile variable(s) or synchronization primitives to avoid this. V741. Consider using a comparison with defined precision: Math.abs(A - B) < Epsilon or Math.abs(A - B) > Epsilon. Consider inspecting the 'for' operator. Consider inspecting the return statement. Possible SQL injection. The analyzer has detected a non-void function with an execution path that does not return a value. The 'x' variable is assigned values twice successively. V1096. Casts between a void pointer and an arithmetic type should not be performed. The 'if' 'else if' construct should be terminated with an 'else' statement. Arrays should not be partially initialized. What should I follow, if two altimeters show different altitudes? MISRA. V817. This file is marked with copyleft license, which requires you to open the derived source code. I am writing a function to validate if the strlen of a string = 26 or not and returning a boolean value however I get an error message stating "error: non-void function does not return a value in all control paths [-Werror,-Wreturn-type]" despite there being no way for a value not to be returned. The 'Foo' pointer is always not equal to NULL. Probably it is a mistake. V3139. The 'alloca' function is used inside the loop. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. Explicit conversion from 32-bit integer type to memsize type. V202. A boy can regenerate, so demons eat him for years. AUTOSAR. V3137. V563. V3171. The line contains control character 0x0B (vertical tabulation). The field will have default value on different threads. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. All analyzer messages were filtered out or marked as false positive. Call of the 'Foo' function will lead to buffer underflow. V3176. It is possible that a typo is present inside the expression. The switch statement does not cover all values of the enum. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. V527. Consider using the extended version of the 'foo' function here. Suspicious subexpression in a sequence of similar comparisons. Consider inspecting the expression. V1095. V2601. Return value is not always used. It's probably an error or un-optimized code. The SUCCEEDED or FAILED macro should be used instead. V688. V1007. V3041. V1069. One is enough. V771. It is possible that a call to 'Start' method is missing. The operator '||' operator is surrounded by opposite expressions 'x' and '!x'. It is possible literal was intended to belong to '??' V562. Exception classes should be publicly accessible. Passing these values into the method will result in an exception. operator works in a different way than it was expected. We will email you at. It is possible that an assigned variable should be checked in the next condition. The '&=' operation always sets a value of 'Foo' variable to zero. Variable of the 'string_view' type references a temporary object, which will be removed after evaluation of an expression. Literal suffixes should not contain lowercase characters. MISRA. Constructor parameter is not used. The opportunity to suppress the warning was overlooked. The 'A' class containing IDisposable members does not itself implement IDisposable. V831. operator instead. The compiler has been asked to treat warnings as errors. V2507. Probably meant: *ptr != zero. This recommendation encompasses ERR33-C. Detect and handle standard library errors. Have a question about this project? V1010. V3153. V1092. The value is assigned to the 'x' variable but is not used. V6089. A double memory deallocation will occur. V3178. V3150. V303. An early return is a return statement that occurs before the last line of a function. Potentially tainted data is used as a path. The analyzer has detected a non-void function with an execution path that does not return a value. Not the answer you're looking for? This condition was already verified in previous line. V1046. Odd semicolon ';' after 'if/for/while' operator. Function marked as 'noreturn' may return control. V553. V6079. V618. Inspect the Nth argument. Consider checking for typos. V2607. A private Ctor(SerializationInfo, StreamingContext) constructor in unsealed type will not be accessible when deserializing derived types. As your code stands, if candidate_count is greater than 0 the loop will iterate once and then unconditionally return false, which I don't think is what you want. V3154. The result of '&' operator is '0' because one of the operands is '0'. When we call a function by itself (e.g. V702. Use volatile variable(s) or synchronization primitives to avoid this. V577. The '+' operation is executed. V1051. Consider using a comparison with defined precision: fabs(A - B) < Epsilon or fabs(A - B) > Epsilon. V571. V2577. Consider replacing this function with 'std::uncaught_exceptions'.

Al Neuharth Political Party, Articles W