compiler-warnings

How to make OCaml compiler report unused functions?

人走茶凉 提交于 2020-05-30 04:25:49
问题 I wonder if is there any ways to make OCaml compiler report warnings about unused functions ? I googled but there are not much topics discussed about this feature. In particular, in the following program, there are two functions "foo" and "bar" which are declared but "bar" is not used in the "_" function. So I think that the OCaml compiler should report "bar" as an unused function. let foo x y = x + y let bar x y z = x + y + z (* should be reported unused *) let _ = let x = foo 1 2 in x 回答1:

Are there cases of complilers not being able to diagnose missing return?

泪湿孤枕 提交于 2020-04-13 03:57:04
问题 I did some research to find out why a missing return cannot be an error but is undefined behavior instead. I found this comment in a bug report that uses the following example to illustrate why it cannot be an error: template<typename T> T maybe_call(std::function<T(void)> f) { if (f) return f(); else abort_program(); // Cannot write a return here, because we have no way to create a value of t } Note that this example is completely valid code. It has no return on all branches, but still there

Are there cases of complilers not being able to diagnose missing return?

大憨熊 提交于 2020-04-13 03:56:32
问题 I did some research to find out why a missing return cannot be an error but is undefined behavior instead. I found this comment in a bug report that uses the following example to illustrate why it cannot be an error: template<typename T> T maybe_call(std::function<T(void)> f) { if (f) return f(); else abort_program(); // Cannot write a return here, because we have no way to create a value of t } Note that this example is completely valid code. It has no return on all branches, but still there

“'getenv': This function or variable may be unsafe.” - really?

被刻印的时光 ゝ 提交于 2020-04-12 19:46:13
问题 I'm using MSVC to compile some C code which uses standard-library functions, such as getenv() , sprintf and others, with /W3 set for warnings. I'm told by MSVC that: 'getenv': This function or variable may be unsafe. Consider using _dupenv_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS Questions: Why would this be unsafe, theoretically - as opposed to its use on other platforms? Is it unsafe on Windows in practice? Assuming I'm not writing security-oriented code - should I

Why am I getting a warning for this range-based for loop in C++?

一曲冷凌霜 提交于 2020-04-10 12:51:29
问题 I am currently self-teaching myself C++ using Bjarne Stroustrup's book (2nd ed). In one of the examples, he uses a range-for-loop to read the elements in a vector. When I wrote and compiled the code for myself I get this warning. When I run the code, it seems to be working and calculates the mean. Why am I receiving this warning and should I ignore it? Also, why is the range-for using int instead of double in the example, but still returns a double? temp_vector.cpp:17:13: warning: range-based

Why am I getting a warning for this range-based for loop in C++?

允我心安 提交于 2020-04-10 12:49:37
问题 I am currently self-teaching myself C++ using Bjarne Stroustrup's book (2nd ed). In one of the examples, he uses a range-for-loop to read the elements in a vector. When I wrote and compiled the code for myself I get this warning. When I run the code, it seems to be working and calculates the mean. Why am I receiving this warning and should I ignore it? Also, why is the range-for using int instead of double in the example, but still returns a double? temp_vector.cpp:17:13: warning: range-based

Why am I getting a warning for this range-based for loop in C++?

孤街浪徒 提交于 2020-04-10 12:48:03
问题 I am currently self-teaching myself C++ using Bjarne Stroustrup's book (2nd ed). In one of the examples, he uses a range-for-loop to read the elements in a vector. When I wrote and compiled the code for myself I get this warning. When I run the code, it seems to be working and calculates the mean. Why am I receiving this warning and should I ignore it? Also, why is the range-for using int instead of double in the example, but still returns a double? temp_vector.cpp:17:13: warning: range-based

warning: ignoring return value of ‘fscanf’ in C

℡╲_俬逩灬. 提交于 2020-02-24 11:08:08
问题 I have the following code in C: (void)fscanf(fp, "%*d %*d %d %d %d\n",&z, &e, &a); I cast the call to void as the return value of fscanf is irrelevant for me. But I get the following warning when compiling: warning: ignoring return value of ‘fscanf’, declared with attribute warn_unused_result [-Wunused-result] (void)fscanf(fp, "%*d %*d %d %d %d\n",&z, &e, &a); Shouldn't the '(void)' have taken that warning out? 回答1: That's a nice warning, since ignoring the return value of fscanf() could lead

-Wsequence-point warning - what does it mean and does it violate ANSI C standard?

℡╲_俬逩灬. 提交于 2020-02-22 06:11:21
问题 In line tab[i] = tab[i+1] - tab[i] + (tab[i+1] = tab[i]); I have a warning [Warning] operation on '*(tab + ((sizetype)i + 1u) * 4u)' may be undefined [-Wsequence-point] I want to swap these two integer arrays elements without temporary variable and without violation of ANSI C. Program still works, but is it ok? 回答1: Your code relies on behaviour that is not covered by the standard. So your code may behave differently on different compilers, different versions of the same compiler and even

gcc warning: function used but not defined

こ雲淡風輕ζ 提交于 2020-02-17 23:03:04
问题 I am getting the warning: function used but not defined . I have static __inline__ in header file say a.h . The header file is included in a.c . I would like put all those inline function which are in header files into the .c files. Following code gives the idea of my problem. Orginal code: a.h: static __inline__ function1(){ function definition; } I changed: a.h: static function1(); a.c: #include "a.h" static function1(){ function definition; } On doing above I got the warning: warning: