compiler-warnings

Failing compilation if return value is unused for a certain type

☆樱花仙子☆ 提交于 2019-12-04 12:19:06
I would like to make compilation fail for some function call but not others. The function call that I want to fail are those that do not handle return values when the value is of a certain type. In the example below, not handling a function returning Error is a compilation error but not handling a function that returns anything else should succeed just fine. Note: our runtime environment (embedded) does not allow us to use the following constructs: RTTI, exceptions. This code only needs to compiler with Clang, I would prefer not having to annotate each function. We prefer a solution that fails

“Recursive on All Control Paths” error when implementing factorial function

我的未来我决定 提交于 2019-12-04 10:25:16
For class I have an assignment: Write a C++ program that will output the number of distinct ways in which you can pick k objects out of a set of n objects (both n and k should be positive integers). This number is given by the following formula: C(n, k) = n!/(k! * (n - k)!) Your program should use two value-returning functions. The first one should be called factorial and should return n! . The second function should be called combinations and should return n!/(k! * (n - k)!). Test your program for different values of n and k five times (count-controlled loop). I came up with a solution:

Scala pattern matching on generic type with TypeTag generates a warning while ClassTag not?

霸气de小男生 提交于 2019-12-04 09:57:08
I have two very similar methods. The only difference is the use of ClassTag and TypeTag : def matchClass[A: ClassTag](v: Any) = v match { case a: A => "it's A" case _ => "not A" } def matchType[A: TypeTag](v: Any) = ... // same code as matchClass A compile warning will show for matchType , but not for matchClass : abstract type pattern A is unchecked since it is eliminated by erasure case a: A Why is there a warning? why does it show only for TypeTag and not ClassTag ? You don't see a warning for classTag because that check simply works for those: scala> matchClass[Int]("aaa") res82: String =

Is there a way to get VS2008 to stop warning me about unreachable code?

强颜欢笑 提交于 2019-12-04 09:54:34
问题 I have a few config options in my application along the lines of const bool ExecuteThis=true; const bool ExecuteThat=false; and then code that uses it like if(ExecuteThis){ DoThis(); } if(ExecuteThat){ DoThat(); } //unreachable code warning here The thing is, we may make slightly different releases and not ExecuteThis or ExecuteThat and we want to be able to use consts so that we don't have any speed penalties from such things at run time. But I am tired of seeing warnings about unreachable

gcc: How to use __attribute((__may_alias__)) properly to avoid “derefencing type-punned pointer” warning

守給你的承諾、 提交于 2019-12-04 09:47:36
问题 I've got some code that uses type-punning to avoid having to call a member "object"'s constructor and destructor unless/until it's actually necessary to use the object. It works fine, but under g++ 4.4.3, I get this dreaded compiler warning: jaf@jeremy-desktop:~$ g++ -O3 -Wall puns.cpp puns.cpp: In instantiation of ‘Lightweight<Heavyweight>’: puns.cpp:68: instantiated from here puns.cpp:12: warning: ignoring attributes applied to ‘Heavyweight’ after definition puns.cpp: In destructor

Intel C++ Compiler warning 167 when non-const argument is passed as const parameter [duplicate]

怎甘沉沦 提交于 2019-12-04 09:29:36
This question already has an answer here: Why isn't it legal to convert “pointer to pointer to non-const” to a “pointer to pointer to const” 5 answers I have a large codebase that recently moved from Microsoft's compiler to the Intel C++ Compiler. Our team's goal is compilation without warnings in the mainline. Since the switch, one instance of warning 167 has confounded me. If I compile the following code: int foo(const int pp_stuff[2][2]) { return 0; } int foo2(const int pp_stuff[][2]) { return 0; } int main(void) { int stuff[2][2] = {{1,2},{3,4}}; foo(stuff); foo2(stuff); return 0; } The

Is there any C++ compiler which can issue a warning for a dangling reference?

…衆ロ難τιáo~ 提交于 2019-12-04 09:07:12
Given the following code, where x is a dangling const reference to a vanished object, and is therefore undefined behavior. auto get_vec() { return std::vector<int>{1,2,3,4,5}; } const auto& x = get_vec().back(); It seems like neither GCC 7.3 , Clang 6.0 and MSVC is able to emit a warning, even with all warnings enabled. Does anyone know if it is any way to emit a warning in these cases? Is there any difference between const auto& and auto&& in these cases? Note, if back() would return by value, it wouldn't be undefined behavior as the lifetime temporary object x is extended to function scoop.

What is clang's 'range-loop-analysis' diagnostic about?

℡╲_俬逩灬. 提交于 2019-12-04 07:33:41
Background: Consider the following example : #include <iostream> #include <vector> int main() { std::vector<bool> vectorBool{false, true}; for(const auto &element : vectorBool) std::cout << std::boolalpha << element << ' '; return 0; } It emits the warning: test.cpp:6:21: warning: loop variable 'element' is always a copy because the range of type 'std::vector<bool>' does not return a reference [-Wrange-loop-analysis] for(const auto &element : vectorBool) std::cout << std::boolalpha << element << ' '; ^ test.cpp:6:9: note: use non-reference type 'std::_Bit_reference' for(const auto &element :

Eclipse - @SuppressWarnings(“javadoc”) does not work

烂漫一生 提交于 2019-12-04 07:20:26
I have my Eclipse configured to show warnings on missing javadoc comments and tags for public elements. That comes very usefull for me in order to keep my code well documented. But sometimes I have a class, where I have several constants describing for example states of DFA or something.. theres no need to document theese constant, because they are self-explaining.. So I added annotation @SuppressWarnings("javadoc") to the class and here's my point - Eclipse does not concider the annotation and still shows warnings on missing javadocs.. @SuppressWarnings("all") does the job, but that has side

Swap occurrences of two most frequent letters in a string

自古美人都是妖i 提交于 2019-12-04 07:03:53
问题 I don't know what is the problem in my code, but when I compile I get: warning: passing arg 2 of `strcspn' makes pointer from integer without a cast Here is the code: #include <stdio.h> #include <stdlib.h> #include <string.h> #define STR_LEN 50 int main(void) { int i = 0, j = 0, length = 0, count1 = 0, count2 = 0, count3 = 0; char letter3 = 'a', letter2 = 'a', string[STR_LEN] = { 0 }; length = strlen(string); printf("Enter a sentence: "); fgets(string, STR_LEN, stdin); for (i = 0; i < length;