compiler-warnings

How to disable a specific nvcc compiler warnings

纵饮孤独 提交于 2019-11-27 05:37:19
问题 I want to disable a specific compiler warning with nvcc , specifically warning: NULL reference is not allowed The code I am working on uses NULL references are part of SFINAE, so they can't be avoided. An ideal solution would be a #pragma in just the source file where we want to disable the warnings, but a compiler flag would also be fine, if one exists to turn off only the warning in question. 回答1: It is actually possible to disable specific warnings on the device with NVCC. It took me ages

Can I make GCC warn on passing too-wide types to functions?

流过昼夜 提交于 2019-11-27 05:25:42
Following is some obviously-defective code for which I think the compiler should emit a diagnostic. But neither gcc nor g++ does, even with all the warnings options I could think of: -pedantic -Wall -Wextra #include <stdio.h> short f(short x) { return x; } int main() { long x = 0x10000007; /* bigger than short */ printf("%d\n", f(x)); /* hoping for a warning here */ return 0; } Is there a way to make gcc and g++ warn about this? On a side note, do you have another compiler which warns about this by default or in a fairly common extra-warnings configuration? Note: I'm using GCC (both C and C++

gcc failing to warn of uninitialized variable

北慕城南 提交于 2019-11-27 05:24:40
The following code has a variable that may be uninitialized. It seems that gcc should be generating a warning but isn't: $ cat a.c int foo(int b) { int a; if (b) a = 1; return a; } $ gcc-4.7 -c -Wall -Wmaybe-uninitialized -o a.o ./a.c $ gcc-4.7 -v Using built-in specs. COLLECT_GCC=gcc-4.7 COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.3-2ubuntu1~12.04' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr -

How to ignore compiler warning when using Obsolete attribute on a class used with a Knowntype attribute

本小妞迷上赌 提交于 2019-11-27 05:24:21
问题 So we are trying to deprecate some of our existing classes, and have started marking them as obsolete with the ObsoleteAttribute so they will stop being used. The fact that using the KnownType attribute with a type that is marked with the Obsolete attribute and is causing a compiler warning is expected. However, in our project we have warnings treated as errors so ignoring the warning isn't an option. Is there a compiler directive to suppress this warning? The following usage causes a

why am I not getting an “used uninitialized” warning from gcc in this trivial example? [duplicate]

蹲街弑〆低调 提交于 2019-11-27 04:49:24
问题 This question already has an answer here: Why is there not any warning on a declaration without initialization in a for loop? 1 answer Once again a stupid uninitialized variable error in How to fix this segmentation error in a sequence inverting program?. So I was going to repeat the "please use -Wall flags" comment, but when I tested the code against warnings, I found no warnings reported to my great surprise. So I trimmed it down to this below (this code makes no sense for execution

In C++, when can two variables of the same name be visible in the same scope?

纵饮孤独 提交于 2019-11-27 04:38:43
问题 This code illustrates something that I think should be treated as bad practice, and elicit warnings from a compiler about redefining or masking a variable: #include <iostream> int *a; int* f() { int *a = new int; return a; } int main() { std::cout << a << std::endl << f() << std::endl; return 0; } Its output (compiled with g++): 0 0x602010 I've looked at a couple references (Stroustrup and The Complete C++ Reference) and can't find anything about when and why this is allowed. I know that it's

What does casting to `void` really do?

穿精又带淫゛_ 提交于 2019-11-27 04:29:05
An often used statement like (void)x; allows to suppress warnings about unused variable x . But if I try compiling the following, I get some results I don't quite understand: int main() { int x; (short)x; (void)x; (int)x; } Compiling this with g++, I get the following warnings: $ g++ test.cpp -Wall -Wextra -o test test.cpp: In function ‘int main()’: test.cpp:4:13: warning: statement has no effect [-Wunused-value] (short)x; ^ test.cpp:6:11: warning: statement has no effect [-Wunused-value] (int)x; ^ So I conclude that casting to void is very different from casting to any other types, be the

Will a “variableName;” C++ statement be a no-op at all times?

余生颓废 提交于 2019-11-27 03:46:35
In C++ sometimes a variable will be defined, but not used. Here's an example - a function for use with COM_INTERFACE_ENTRY_FUNC_BLIND ATL macro: HRESULT WINAPI blindQuery( void* /*currentObject*/, REFIID iid, void** ppv, DWORD_PTR /*param*/ ) { DEBUG_LOG( __FUNCTION__ ); //DEBUG_LOG macro expands to an empty string in non-debug DEBUG_LOG( iid ); iid; // <<<<<<<----silence compiler warning if( ppv == 0 ) { return E_POINTER; } *ppv = 0; return E_NOINTERFACE; } In the above example iid parameter is used with DEBUG_LOG macro that expands into an empty string in non-debug configurations. So

C++: warning: C4930: prototyped function not called (was a variable definition intended?) [duplicate]

泪湿孤枕 提交于 2019-11-27 03:27:43
问题 This question already has an answer here : Is there any difference between `List x;` and `List x()` (1 answer) Closed 5 years ago . I have a class that does not have a default constructor, I created a variable without giving parameters by mistake, but instead of a nice compiler error, I got a linker error, where I couldn't find the line of code that was causing it. In the end, I managed to find the code that caused this, and only then I noticed that I was getting this warning: C++: warning:

Is it problematic to assign a new value to a method parameter?

夙愿已清 提交于 2019-11-27 03:09:02
问题 Eclipse has an option to warn on assignment to a method's parameter (inside the method), as in: public void doFoo(int a){ if (a<0){ a=0; // this will generate a warning } // do stuff } Normally I try to activate (and heed) almost all available compiler warnings, but in this case I'm not really sure whether it's worth it. I see legitimate cases for changing a parameter in a method (e.g.: Allowing a parameter to be "unset" (e.g. null) and automatically substituting a default value), but few