-isystem for MS Visual Studio C++ Compiler - visual-studio

I usually like to have a lot of warnings enabled when programming. However, some libraries contains code that easily causes warnings (.., python, Qt, ..). When compiling with gcc I can just use -isystem instead of -I to silence that. How can I do the same with the MS compiler? I know of the warning #pragma, but I would like a solution that does not involve compiler specific code all over the place. I also know that I can turn off specific warnings, but that is not what I want either.
BTW: isystem should be a tag of this question, but I was not allowed to do that..
SUMMARY: I want to see all warnings from my code, and no warnings from external code.

As of 2017-08-17 this still seems impossible.
I added a feature request here:
https://developercommunity.visualstudio.com/content/problem/96411/impossible-to-ignore-warnings-from-system-librarie.html
Update 2018:
The issue is now closed as fixed and is available in the standard MS VS installation [source].
A blog post from the MS team goes through the new features [here].
The solution from MS is flexible. You can not only differentiate using paths like you do with --isystem, but for example also by whether you use #include "" or #include <>. The blog post is worth a read to see all the various customization points.

This now exists under /experimental:external /external:I system_include_path /external:W0. See https://blogs.msdn.microsoft.com/vcblog/2017/12/13/broken-warnings-theory/ for many more details.

No clue why MS never picked this up.
We can only try voting on https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/14717934-add-a-cl-exe-option-for-system-headers-like-gcc-s

No, MSVC doesn't have an -isystem equivalent.
look at the output output from cl /? :
/wd disable warning n
/we treat warning n as an error
/wo issue warning n once
/w set warning level 1-4 for n
Note that this disables the warnings for your entire project; I remember when using Qt I'd rather change it's main header with the #pragma warning disable and enable at the end again so I could still see all warnings for my own source.
Edit the author edited his question, updated answer: there is no way to get your code with warnings and Qt code without warnings using compiler flags: how are you going to tell the compiler what is 'your' code?
Note that the above flags can be applied at file level as well, so this would allow you to disable the warnings for only those files in which you include Qt headers, but that still means you cannot see them for your own code in that files.
So I stay with the answer above; it is not quite pretty, but I'm pretty sure it's the only way: use #pragma at the beginning and the end of the Qt header(s). Either change the Qt headers (even more ugly), or choose a less invasive way like this:
//your source/header file
#include "shutuppqt.h"
#include <QString>
#include "enableallwarnings.h"
example "shutuppqt.h"
#ifdef MSVC
#pragma warning ( disable : 4222 ) //or whatever warning Qt emits
#else
//....
#endif
example "enableallwarnings.h"
#ifdef MSVC
#pragma warning ( enable : 4222 ) //or default instead of enable
#else
//....
#endif

Related

VS Code not defining _WIN32

I have exactly the opposite problem to VSCode turn of _WIN32 define - Visual Studio Code is failing to define _WIN32 for me. This is in a cross-platform project that is being developed on Windows with the Microsoft compiler, but needs to also be able to compile on Linux, so I have
#ifdef _WIN32
#include <windows.h>
failing, and VS Code then marks all references to Windows API types etc. with red underlines. (The include mechanism itself is working fine, e.g. it has no problem including regular C++ headers.)
Is there any known reason why VS Code on Windows might fail to define _WIN32? The question I linked suggests it should, and I haven't knowingly changed any settings related to it.
Most likely, the problem is VSCode is using the wrong C++ compiler to gather the predefined macros, and that compiler does not predefine _WIN32.
To check, in Command Palette (Ctrl+Shift+P), run "C/C++: Log Diagnostics". The output will show you which compiler VSCode found and what it detected as its built-in include path and preprocessor defines. If my guess is correct, the diagnostics will show the wrong compiler being used, and _WIN32 missing.
Assuming so, to solve this, use the command Palette to run "C/C++: Edit Configurations (UI)", then set "Compiler path" to point at your compiler executable (cl.exe in this case). That should solve the problem because VSCode will then query that compiler to determine the predefined macros, which will include _WIN32. Re-run the diagnostics to confirm.
(I just gave a similar answer to the question linked to in the question above, as I think both questions have essentially the same problem and solution, just with different details.)

Silencing "Documentation issue" warnings in Xcode?

E.g.
'#param' command used in a comment that is not attached to a function declaration
This warning is valid, however, I am compiling 3rd party code and wish to not have to alter the original source.
I am running Xcode 8.2.1.
I was able to suppress these warnings by going to
Project -> Build Settings -> Apple LLVM 8.1 - Warnings - All Languages, and switching the "Documentation Comments" to No.
(To find the setting, I typed "Documentation" into the search box under Build Settings.)
This solved it for me, surpassing the warnings only in the third party library headers. Just wrap the problematic header #includes with these pragmas:
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdocumentation"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#pragma clang diagnostic pop
this is a combination of a hint from
Konchog and Vladimir Grigorov’s super helpful answer here.

CUDA __syncthreads() compiles fine but is underlined with red

I have been working with CUDA 4.2 for a week now and I have a little problem.
When I write the __syncthreads() function it becomes underlined and looks like it is wrong...
Then if I put the mouse on the function it appears a message writing:
identifier __syncthreads(); is undefined.
but when i compile my project the output form build says:
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
So I am guessing that everything works fine but the fact that Visual Studio underlines the function is confusing me...How can I make Visual studio to know that this function is defined before the compiling process?
NOTE:The same thing happens with the kernel call: kernel<<<...,...>>> where the third "<" is underlined red too...
I know that this probably is a minor problem but i want to solve it...Thanks a lot!
I am using Visual Studio 2010 on win7 with Cuda 4.2 and Nsight 2.2
I added the following few lines to the top of the cu file and it began to recognize these functions. For some reason, Intellisense did not pick up this #define:
#ifndef __CUDACC__
#define __CUDACC__
#endif
I lost some color-coding in the code, but I no longer get strange false positive errors.
I am using CUDA 9.1 and Visual Studio 2017 15.6.4. The following code helps me eliminate the "__syncthreads() is undefined" error.
//for __syncthreads()
#ifndef __CUDACC__
#define __CUDACC__
#endif
#include <device_functions.h>
However, this method is not recommended because it may bring unpredictable side effects. Another method to solve this intellisense warning is:
#ifdef __INTELLISENSE___
// in here put whatever is your favorite flavor of intellisense workarounds
#endif
Reference:
__syncthreads(); is undefined need a help
I have CUDA 8.0 and Visual Studio 2015 and I had the same issue.
The below lines helped me:
After these lines: (already in code)
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
I added these lines:
//for __syncthreads()
#ifndef __CUDACC_RTC__
#define __CUDACC_RTC__
#endif // !(__CUDACC_RTC__)
#include <device_functions.h>
It's based on this link: https://devtalk.nvidia.com/default/topic/1009723/__syncthreads-and-atomicadd-are-undefined-in-visual-studio-2015/
Experienced this when trying to define the body of __global__ functions in .cuh files. Moving the body of the functions into .cu source-file solved it.
However, it means that some of my templated functions can't use essential things like __syncthreads(), because templates might have to be defined in a .cuh header.
So, you might need to abandon function templates and instead stick to several functions, each with a slightly different name.
The other solutions either did not solve the same issue occurring in Eclipse 2021-06 with CMake 3.16.3, or produced the following warning with CUDA Runtime Version = 10.1:
/usr/include/device_functions.h:54:2: warning: #warning "device_functions.h is an internal header file and must not be used directly. This file will be removed in a future CUDA release.
The following gave proper highlighting and code completion in Eclipse, and it didn't produce compile warning:
#ifndef __CUDACC__
#define __CUDACC__
#include <device_functions.h>
#endif

Is there any way to disable all warnings with a pragma in clang or gcc?

GCC and clang let you compile with -w to disable all warnings, but I can't see a #pragma equivalent of it. I can see only pragma support for disabling individual files.
I need this because I have code that I want to compile with high warning levels but which necessarily compiles third party code which generates arbitrary warnings.
You can kind of do it with GCC, almost, using #pragma GCC diagnostic ignored, but unluckily not very well, see here.
The problem is that you cannot just "disable all", you have to disable each single one. Plus, for some warnings it doesn't work (and the docs don't tell you which ones...).
My guess is that this somewhat preliminary and will (hopefully) be improved in the next version.

How to suppress all warnings from non-solution files in VisualStudio

I wonder, whether it is possible to suppress warnings coming from included library files, while showing all solution-file warnings in Visual Studio?
I have a solution that uses stingray library. When I build the solution I keep getting numerous warnings from stingray files, so I am loosing warnings from my files (that are actually in solution and that I own and edit). For me there is no value in included warnings, since I cannot edit those files, but I do need to see all my warnings.
Is there any way I could do it?
Added after first answer:
Sorry for being not clear - I am not building third party library - I am linking the libraries they provided, but I am including their headers in my own - as a results I have numerous warnings in "file included from..." - is there any way to sort that out?
--
Thanks in advance
#pragma warning(push ,3)
# include third-party h-files
#pragma warning(pop)
Another way:
#pragma warning(disable: 4507 4510)
# include third-party h-files
#pragma warning(default: 4507 4510)
Open your third party library's project properties, you can minimize your warning level in build tab.

Resources