warning non void function does not return a value

warning non void function does not return a value

An excessive type cast or check. The compiler has been asked to warn when a function has a control path that doesn't return a value (although not mentioned in the message, throwing a value and possibly calling a non-returning function may also be considered acceptable). Particularly, if during the function execution an exception is thrown and is not caught in the body of the same function, there will be no undefined behavior. V1060. It's probably an error or un-optimized code. It may be an error. Trying to use the return value from the function will most likely cause a segmentation fault. Constant expression in switch statement. Memory is allocated and released multiple times inside the loop body. Examine the substrings "abc" and "abcd". How to enter the PVS-Studio license and what's the next move, Release history for previous versions (before 7.00), Getting acquainted with the PVS-Studio static code analyzer on Windows, Build-system independent analysis (C and C++), Direct integration of the analyzer into build automation systems (C and C++), PVS-Studio C# installation on Linux and macOS, How to run PVS-Studio C# on Linux and macOS, Installing and updating PVS-Studio C++ on Linux, Installing and updating PVS-Studio C++ on macOS, How to run PVS-Studio C++ on Linux and macOS, Get started with PVS-Studio in Visual Studio, Using PVS-Studio with JetBrains Rider and CLion, Analyzing Visual Studio / MSBuild / .NET projects from the command line using PVS-Studio, Cross-platform analysis of C and C++ projects in PVS-Studio, How to use the OWASP diagnostic group in PVS-Studio, Analysis of C++ projects based on JSON Compilation Database, How to integrate PVS-Studio into CMake with a CMake module, How to analyze Unity projects with PVS-Studio, Integration of PVS-Studio analysis results into SonarQube, Speeding up the analysis of C and C++ code through distributed build systems (Incredibuild), How to display the analyzer's most interesting warnings, Baselining analysis results (suppressing warnings for existing code), Handling the diagnostic messages list in Visual Studio, How to view and convert analyzer's results, Viewing analysis results with C and C++ Compiler Monitoring UI, Notifying the developer teams (blame-notifier utility), Viewing reports in a SARIF format in Visual Studio Code, Filtering and handling the analyzer output through diagnostic configuration files (.pvsconfig), Excluding files and directories from analysis, Using the PVS-Studio extension for Visual Studio Code, How to use the PVS-Studio extension for Qt Creator, Analysis configuration file (Settings.xml). The 'ThreadStatic' attribute is applied to a non-static 'A' field and will be ignored. V615. V580. Probably meant: '(*pointer)++'. MISRA. OWASP. MISRA. V6015. 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 is possible that a typo is present inside the expression. Signed integer overflow in arithmetic expression. If you wish to call constructor, use 'this->Foo::Foo(.)'. V6034. MISRA. Consider inspecting virtual function arguments. V2564. Shift by N bits is greater than the size of type. Potentially tainted data is used to create query. Probably meant: '\xNN'. Identifiers declared in the same scope and name space should be distinct. A smart pointer may not destroy an object correctly. An exception handling block does not contain any code. operators are used for accessing members of the same object. V509. Consider inspecting 'X'. Pointer was used after the memory was released. V791. V611. V593. You signed in with another tab or window. MISRA. There is a probability of logical error presence. GCC options: warning on non-void functions without a return statement, Type No return, in function returning non-void, no return in function using switch statement, No return statement warning in function returning non-void. V546. V6041. V5608. Suspicious semicolon ';' after 'if/for/while' operator. The resulting value could be inaccurate. This program prints the letters A and B on separate lines. V6103. V3041. Such a function results in undefined behavior. Explicit conversion from 'float/double' type to signed integer type. An excessive expression. Do not define an unnamed namespace in a header file. In case of false, your function will not return anything and result in compilation error. MISRA. ** 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. MISRA. This return value is also printed. V3131. V221. No return statement is required. External object or function should be declared once in one and only one file. V6033. Constructor contains potentially uninitialized members. Destructor of 'Foo' class is not declared as virtual. V816. V3081. The body of a loop\conditional statement should be enclosed in braces. This can result in an overflow. This file is marked with copyleft license, which requires you to open the derived source code. Stack of original exception could be lost. C compiling Error: non-void function does not return a value in all control paths - CS50. The 'first' argument of 'Foo' function is equal to the 'second' argument. WPF: readonly field of 'DependencyProperty' type is not initialized. There should be no attempt to write to a stream that has been opened for reading. V512. The use of 'if (A) {} else if (A) {}' pattern was detected. Content Discovery initiative April 13 update: Related questions using a Review our technical responses for the 2023 Developer Survey, C, error: control reaches end of non-void function [-Werror,-Wreturn-type], Control may reach end of non-void function [-Werror,-Wreturn-type]. V2510. V574. Potentially tainted data is used in the URL. The resulting value may be inaccurate. Use of constant NN. V3087. It is possible that a line was commented out improperly, thus altering the program's operation logic. One, the C standard specifies the behavior of, C error: non-void function does not return a value in all control paths [-Werror,-Wreturn-type], the assembly GCC 11.2 generates for this with, testing by changing the function return type to int and changing the returns to, How a top-ranked engineering school reimagined CS curriculum (Ep. V1064. Which language's style guidelines should be used when writing code that is supposed to be called from another language? Don't use terminating functions in library code. V2528. It is possible that this 'else' branch must apply to the previous 'if' statement. What "benchmarks" means in "what are benchmarks for?". Controlling expressions should not be invariant. Just make it return, @NathanOliver One could imagine a slightly more complex example which was fully reasonable, like. For more information, see "Behavior" in Function Statement. V605. Possible incorrect order of arguments passed to method. V3011. V825. Pointer to array is out of array bounds. V5618. V2597. Consider casting operands, not the result. The expression is excessive or contains a misprint. The global namespace should only contain 'main', namespace declarations and 'extern "C"' declarations. 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. MISRA. Unchecked tainted data is used in expression. Type casting is used 2 times in a row. Function receives an odd argument. V528. Consider inspecting the expression. It is possible that a backslash should be used instead: '\r'. Consider inspecting the 'for' operator. The expression is excessive or contains a logical error. All integer constants of unsigned type should have 'u' or 'U' suffix. It is not advised to declare type 'T' as 32-bit type. V2013. The expression is excessive or contains a logical error. The 'swap' function may interchange a variable with itself. V808. It is likely that a wrong variable is being incremented inside the 'for' operator. V1085. V665. It's odd that this method always returns one and the same value of NN. V3532. V6045. V704. A value of variable is not modified. The expression is always false. V2508. MISRA. V3093. V3517. The 'throw' keyword could be missing. Two or more case-branches perform the same actions. Not all the members of type are serialized inside 'GetObjectData' method. This can quickly overflow stack. The value is assigned to the 'x' variable but is not used. The 'strcmp' function returns 0 if corresponding strings are equal. V3165. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. 1. V5007. V2008. The argument of the method is not expected to be null. The object was used after it was verified against null. AUTOSAR. Site design / logo 2023 Stack Exchange Inc; user contributions licensed under CC BY-SA. V3541. It is possible that an incorrect variable is compared with null after type conversion using 'as' keyword. Possible XPath injection. Unexpected uint64 behaviour 0xFFFF'FFFF'FFFF'FFFF - 1 = 0? V702. V3057. Wrong variable is probably used in the for operator as an index. V639. The report_ratio function has a void return type, so it doesn't need to explicitly return a value. Pointer to local variable 'X' is stored outside the scope of this variable. V5612. Consider specifying execution policy explicitly. Check for missing 'throw' keyword. V513. V812. Update: You need to make your function return a vector in every condition as suggested in comments. The .exe and .i files are not supported. The expression of 'foo(foo(x))' pattern is excessive or contains an error. V3116. Is a return statement mandatory for C++ functions that do not return void? V3023. Not all IDisposable members are properly disposed. AUTOSAR. Please attach your files here. The first 'if' statement contains function return. Parameter is not used inside method's body. V798. Consider naming the object. Check the array initialization. Consider checking the first actual argument of the 'Foo' method. V6094. Use of two opposite conditions. Consider verifying the initializer. Incorrect shifting expression. V3084. V664. The 'Foo(Foo)' class member is initialized with itself. You may or may not use the return . Such a pointer will become invalid. Perhaps, this statement should have been compared with something else. The expression is checked for compatibility with type 'A', but is cast to type 'B'. Consider inspecting 'X'. V660. 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. You are assuming that loop will always run, but, what if an empty string ends up getting submitted? Possible typo in the spelling of a pre-defined macro name. Consider inspecting the 'for' operator. V5303. The 'operator &&', 'operator ||', 'operator ,' and the unary 'operator &' should not be overloaded. If you cant find an answer to your question, fill in the form below and our developers will contact you. Which ability is most related to insanity: Wisdom, Charisma, Constitution, or Intelligence? An example of data being processed may be a unique identifier stored in a cookie. Thanks for helping to make the site better for everyone. V551. V2589. MISRA. V520. V3101. The macro with the 'setjmp' name and the function with the 'longjmp' name should not be used. Suspicious literal: '/r'. Unconditional 'break/continue/return/goto' within a loop. Floating-point values should not be tested for equality or inequality. V3104. An exception should be caught by reference rather than by value. Call of 'std::is_constant_evaluated' function always returns the same value. V2590. By clicking Accept all cookies, you agree Stack Exchange can store cookies on your device and disclose information in accordance with our Cookie Policy. To learn more, see our tips on writing great answers. Void functions dont need a return statement. Iterators are passed as arguments to 'Foo' function. V3113. Probably meant: *ptr = zero. V604. Consider inspecting the program's logic. This may break the program's logic. Consider inspecting the expression. The expression is incorrect or it can be simplified. Every 'switch' statement should contain non-empty switch-clauses. V2554. return reverseString return Value of 'A' type is assigned to a pointer of 'B' type. Implicit type conversion N argument of function 'foo' to 32-bit type. triniChillibibi 2 yr. ago This was for my print_winner function in runoff. V6017. V201. Consider replacing the call to the 'at()' method with the 'operator[]'. The object could have been garbage collected before the 'Target' property was accessed. Expression resulting from the macro expansion should be surrounded by parentheses. V6036. V541. Variable with static storage duration is declared inside the inline function with external linkage. Casts between a void pointer and an arithmetic type should not be performed. V2511. Exception classes should be publicly accessible. Functions' declarations with 'Foo' name differ in 'const' keyword only, while these functions' bodies have different composition. If certain compiler flags are passed, this type of error or warning might get suppressed entirely, which will lead to run-time faults if the given function gets called in the program. V6055. V3519. Comparison with 'double.NaN' is meaningless. AUTOSAR. V3154. Postfix increment/decrement is senseless because this variable is overwritten. MISRA. To subscribe to this RSS feed, copy and paste this URL into your RSS reader. The total size limit is 20MB. V3186. The expression is always true/false. New variable with default value is created instead of 'std::unique_lock' that locks on the mutex. But below is not the case so why does it get compile, is there something else expected by Oracle. V2509. V1059. Consider restricting the type parameter to reference types. Code's operational logic does not correspond with its formatting. . : .' should be used here instead of 'foo = bar = baz ? Not all members of a class are initialized inside the constructor. V646. Macro expression is dangerous or suspicious. Avoid using 'this == 0' comparison. V6011. When we call a function in a context that requires a value (e.g. V6078. The function with the 'atof/atoi/atol/atoll' name should not be used. The expression is excessive or contains a logical error. V692. AUTOSAR. By clicking Post Your Answer, you agree to our terms of service, privacy policy and cookie policy. Consider checking the function for an error. The arguments violate the bounds of collection. Excessive type casting: string -> char * -> string. The function with the 'qsort/bsearch' name should not be used. is there a trick to keep in mind when adding your own JSON_THROW? Memory allocation and deallocation functions should not be used. V119. V3180. The result of an assignment expression should not be used. Any label should be declared in the same block as 'goto' statement or in any block enclosing it. Call of the 'Foo' function will lead to buffer overflow. To view the purposes they believe they have legitimate interest for, or to object to this data processing use the vendor list link below. Two or more case-branches perform the same actions. Member 'x' should point to string terminated by two 0 characters. @Sneftel Good point. AUTOSAR. AUTOSAR. Probably it is a mistake. V3156. Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support. V3523. V2536. Suspicious return of an always empty collection. V602. The switch statement does not cover all values of the enum. std::cout doesnt know how to handle this (what value would it output?). The object was created but it is not being used. Function printHi has a void return type, meaning it doesnt return a value. The 'a % b' expression always evaluates to 0. 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 (or even a warning, unless -Wreturn-type or -Wall is used). Assigning the value C to the X variable looks suspicious. Consider inspecting usage of 'Y' counter. A function that does not return a value is called a non-value returning function (or a void function ). V6019. Decreased performance. If a return type isn't specified, the C compiler assumes a default return type of int. 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? V2592. V5605. If you haven't received our response, please do the following: The '? Connect and share knowledge within a single location that is structured and easy to search. It is odd that the body of 'Foo_1' function is fully equivalent to the body of 'Foo_2' function. Overflow check is incorrect. Could a subterranean river or aquifer generate enough continuous momentum to power a waterwheel for the purpose of producing electricity? All integer constants of unsigned type should have 'U' suffix. Extracting arguments from a list of function calls. The 'A' field should probably be returned/assigned instead. V636. The code's operational logic does not correspond with its formatting. Suspicious access to element by a constant index inside a loop. The value of the captured variable will be overwritten on the next iteration of the loop in each instance of anonymous function that captures it. V760. Making statements based on opinion; back them up with references or personal experience. Use of uninitialized variable 'Foo'. The DllMain function throws an exception. V809. V5304. So it does not know if the second strlen will return the same value as the first one. V552. V620. V2576. V5611. V2512. The expression was enclosed by parentheses twice: ((expression)). Suspicious subexpression in a sequence of similar comparisons. V2613. See documentation for details. How can I control PNP and NPN transistors together from one pin? V711. V2519. V3102. The result of the right shift operation will always be 0. V502. But, do are you sure you want your return statement inside your loop to begin with? Use of a pointer to FILE when the associated stream has already been closed. The value of uninitialized variable should not be used. Creating an object with placement new requires a buffer of large size. AUTOSAR. A non-serializable class should not be serialized. Temporary object is created and then destroyed. Not the answer you're looking for? Part of conditional expression is always true/false. V5013. The 'i' variable should probably be incremented instead of the 'n' variable. The main function calls two functions: report_square and report_ratio. Consider re-generating your suppress file to continue updating it. The '&' or '|' operator is applied to bool type value. Unreachable code detected. MISRA. Using 'await' in a critical section may lead to a lock being released on a different thread. V737. Possibly meant: 'A -= B'. V3551. MISRA. V776. Use memsize-type here. Bit shifting of the 32-bit value with a subsequent expansion to the 64-bit type. The 'value' parameter is rewritten inside a property setter, and is not used after that. Intermodular analysis may be incomplete, as it is not run on all source files. V821. V671. After the year 2038, the program will work incorrectly. V3537. V2003. Only values returned from fgetpos() can be used as arguments to fsetpos(). V3039. V6066. What risks are you taking when "signing in with Google"? V682. V2556. Check lines: N1, N2. i'm not sure if this is intentional behavior. Probably it is a mistake. The assignment to a member of the readonly field will have no effect when the field is of a value type. V2583. V6105. V1004. An item with the same key has already been added. The expression of strlen(MyStr.c_str()) kind can be rewritten as MyStr.length(). Thus, the analyzer will not issue a warning for the following code fragment: You can look at examples of errors detected by the V591 diagnostic. Bit fields should only be declared with explicitly signed or unsigned integer type. My advice would be to create a new option Wreturn-pedantic. This may lead to undefined behavior. A bool type variable is incremented. It's possible that ',' should be replaced by ';'. : **non void function does not return a value in all control paths: **. Unexpected uint64 behaviour 0xFFFF'FFFF'FFFF'FFFF - 1 = 0? Expression under 'throw' is a potential null, which can lead to NullReferenceException. Consider inspecting the expression. Priority of the '&&' operator is higher than that of the '||' operator. Then main returns a value of 0 (typically used to report success) to end the program. The '!=' operator should probably be used here. V1094. MISRA. The value should be non-negative. V2565. Character escape is used in multicharacter literal. The analyzer will not issue a warning for the following code fragment: There will also be no undefined behavior if, during the function execution, another function that does not return control, is called. When compiling the above example, your compiler may issue a warning about line 9 being unreachable. Waiting on condition variable without predicate. V542. The 'A' function was called several times with identical arguments. V2014. Consider inspecting the expression. Potentially infinite loop. Suspicious pointer arithmetic. V790. Is it safe to publish research papers in cooperation with Russian academics? Functions of strcmp() kind can return any values, not only -1, 0, or 1. The functions from time.h/ctime should not be used. This causes unspecified or undefined behavior. V691. In such a context, we can only call value-returning functions. The '+' operation is executed. OWASP. Consider inspecting the 'Foo' function call. The 'restrict' specifier should not be used. V532. V2540. Use of jump statements in 'finally' block can lead to the loss of unhandled exceptions. V666. Perhaps, it is a typo and 'X' variable should be used instead of 'Y'. So if you want error for specific warning, say -Wreturn-type, just type return-type without -W part as: $ g++ -Werror=return-type source.cpp In general you should always use -Wall option which includes most common warnings this includes missing return statement also. V2531. operator should have 'bool' type. The return expression is forced to use a floating-point operation by casting one of the operands to double. Consider replacing 'const T' with 'const .. &T' / 'const .. *T'. V793. V3143. no return statement in function returning non-void while using C++, How a top-ranked engineering school reimagined CS curriculum (Ep. V3144. V2002. V673. Suspicious assignment inside the conditional expression of 'if/while/for' statement. MISRA. V2619. If the function has a void return type, this behavior is okay, but may be considered poor style. Variables are initialized through the call to the same function. An argument containing a file path could be mixed up with another argument. The expression of the 'char' type is passed as an argument of the 'A' type whereas similar overload with the string parameter exists. The first 'if' statement contains method return. It is possible that a typo is present inside the expression. V771. V3071. V779. Some diagnostic messages may contain incorrect line number. Can you still use Commanders Strike if the only attack available to forego is an attack against an ally? V6031. Function receives an address of a 'char' type variable instead of pointer to a buffer. [Serializable] attribute is missing. V613. AUTOSAR. The behavior is undefined for arithmetic or comparisons with pointers that do not point to members of the same array. Does the 500-table limit still apply to the latest version of Cassandra? Consider checking the use of this variable. Expressions with pointer type should not be used in the '+', '-', '+=' and '-=' operations. The object was created but it is not being used. Infinite loop is possible. Email? All memory or resources allocated dynamically should be explicitly released. V2563. The stream is checked for EOF before reading from it but is not checked after reading. A private Ctor(SerializationInfo, StreamingContext) constructor in unsealed type will not be accessible when deserializing derived types. Return value of 'Foo' function is required to be used. More than N bits are required to store the value, but the expression evaluates to the T type which can only hold K bits. Function with a non-void return type should return a value from all exit paths. Consider casting operands, not the result. An abnormality within similar comparisons. V3091. 'else' keyword is probably missing. V1087. If total energies differ across different software, how do I decide which software to use? The outer type contains static field/property with identical name. V829. MISRA. Class member is initialized with dangling reference. V3158. The conditional expressions of the 'if' statements situated alongside each other are identical. We must also say what type of enter the function lives returning, e.g. We know it knows for two reasons. Void functions cant be used in expression that require a value. Argument of abs() function is minimal negative value. Allocation of memory by the pattern "(X*)malloc(sizeof(Y))" where the sizes of X and Y types are not equal. V3526. Some of the references in project are missing or incorrect. The result of an assignment expression should not be used. Suspicious getter/setter implementation. A minor scale definition: am I missing something? The variable is never modified. V2617. V1074. AUTOSAR. V2568. V2552. MISRA. V622. Possible incorrect use of '#pragma warning(default: X)'. It is suspicious that the body of 'Foo_1' function is fully equivalent to the body of 'Foo_2' function. Consider replacing the expression 'AA' with 'BB'. Not the answer you're looking for? Conditional expressions of 'if' statements located next to each other are identical. The 'SuspendThread' function is usually used when developing a debugger. The initial value of the index in the nested loop equals 'i'. Argument of the '|' bitwise operation always contains non-zero value. V635. V684. Classes should always be derived from std::exception (and alike) as 'public'. What is an early return, and what is its behavior? The macro with the 'setjmp' name and the function with the 'longjmp' name should not be used. Incorrect index type: 'foo[not a memsize-type]'. We and our partners use cookies to Store and/or access information on a device. Comma operator ',' in array index expression. V5606. V5617. Comparing objects of incompatible types. The 'memset/memcpy' function is used to nullify/copy fields of 'Foo' class. Consider using the 'int' type. The 'X' counter is not used inside a nested loop. Initial and final values of the iterator are the same. The argument should probably be rendered as a constant pointer/reference. V3505. The memory areas must not overlap. V6030. Empirical analysis. V625. English version of Russian proverb "The hedgehogs got pricked, cried, but continued to eat the cactus". Use of '\0xNN' characters. control reaches end of non-void functions -wreturn-type. V1026. V2547.

Does Aperol Need To Be Refrigerated After Opening, $1,500 Centrelink Loan, Articles W