compiler-flags

Forbid integer conversion with precision loss

荒凉一梦 提交于 2021-02-18 06:13:21
问题 How to prevent such code from compiling? #include <vector> #include <limits> #include <iostream> #include <cstdint> int main() { std::vector<int16_t> v; v.emplace_back(std::numeric_limits<uint64_t>::max()); std::cout << v.back() << std::endl; return 0; } g++ and clang with -std=c++14 -Wall -Wextra -Werror -pedantic -Wold-style-cast -Wconversion -Wsign-conversion don't even warn about it. The example also compiles without warnings with std::vector<uint16_t> 回答1: Add -Wsystem-headers to the

NVCC overriding a MSVC flag (EHs)

懵懂的女人 提交于 2021-02-11 15:17:30
问题 To compile my source correctly on Windows, I need to pass the EHs flag to MSVC. This is usually straight forward: cl -EHs -c ... When building for GPU acceleration, I need nvcc to pass this flag along when it invokes cl under the hood. I simply do: nvcc -dc -ccbin cl -Xcompiler -EHs ... yet cl throws a warning: warning C4297: 'someFuncInMyCode': function assumed not to throw an exception but does note: The function is extern "C" and /EHc was specified It seems cl receives the flag EHc ,

NVCC overriding a MSVC flag (EHs)

99封情书 提交于 2021-02-11 15:16:39
问题 To compile my source correctly on Windows, I need to pass the EHs flag to MSVC. This is usually straight forward: cl -EHs -c ... When building for GPU acceleration, I need nvcc to pass this flag along when it invokes cl under the hood. I simply do: nvcc -dc -ccbin cl -Xcompiler -EHs ... yet cl throws a warning: warning C4297: 'someFuncInMyCode': function assumed not to throw an exception but does note: The function is extern "C" and /EHc was specified It seems cl receives the flag EHc ,

What are my available march/mtune options?

时光总嘲笑我的痴心妄想 提交于 2021-02-08 12:22:47
问题 Is there a way to get gcc to output the available -march=arch options? I'm getting build errors (tried -march=x86_64 ) and I don't know what my options are. The compiler I'm using is a proprietary wrapper around gcc that doesn't seem to like -march=skylake . The flags should be the same so I assume whatever options I'd send to gcc to dump architectures would be the same for this wrapper. I managed to cause gcc to error with a bogus parameter and it dumped a list, but I'm not seeing that now

UseConcMarkSweepGC is deprecated, what is its replacement?

自闭症网瘾萝莉.ら 提交于 2021-02-08 12:18:53
问题 A java program is giving this warning, with JRE 10.0.2: Java HotSpot(TM) 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release. What is the recommended replacement for this switch? 回答1: Dropping support for CMS and then removing the CMS code, or at least more thoroughly segregating it, will reduce the maintenance burden of the GC code base and accelerate new development. The G1 garbage collector is intended, in the

Why does clang complain about using variable-length arrays with '-std=c99' flag?

久未见 提交于 2021-01-27 06:35:12
问题 When I compile this experiment code: int main(void) { int foo = 5; char bar[foo]; } with clang and the '-Weverything' or respectively the separate '-Wvla' flag combined with the '-std=c99' flag, I still get the warning: warning: variable length array used [-Wvla] Example here although C99 conform implementations shall, in comparison to later C standards (C11, C18, etc.) - where the VLA-support is optional, support variable length arrays without exception. Why do I still get this warning for

Why there is no compiler error when return statement is not present?

回眸只為那壹抹淺笑 提交于 2021-01-18 07:46:05
问题 Unlike Java, in C/C++ following is allowed : int* foo () { if(x) return p; // what if control reaches here } This often causes crashes and hard to debug problems. Why standard doesn't enforce to have final return for non- void functions ? (Compilers generate error for wrong return value) Is there any flag in gcc/msvc to enforce this ? (something like -Wunused-result ) 回答1: It is not allowed (undefined behaviour). However, the standard does not require a diagnostic in this case. The standard

What does the clang compiler's `-Weverything` option include and where is it documented?

╄→尐↘猪︶ㄣ 提交于 2021-01-01 09:59:48
问题 clang, but NOT gcc, has a -Weverything option which appears to include things such as -Wpedantic . You can test it here: https://godbolt.org/z/qcYKd1. See the top-right of the window for where I have typed in -Weverything as an explicit compiler option. Notice the -Wvla-extension warning we get since we are relying on a C99 extension in C++ in this case, and we have -Weverything set. We get the same warning if we just use -Wpedantic , as shown here: https://godbolt.org/z/M9ahE4, indicating

What does the clang compiler's `-Weverything` option include and where is it documented?

浪尽此生 提交于 2021-01-01 09:59:27
问题 clang, but NOT gcc, has a -Weverything option which appears to include things such as -Wpedantic . You can test it here: https://godbolt.org/z/qcYKd1. See the top-right of the window for where I have typed in -Weverything as an explicit compiler option. Notice the -Wvla-extension warning we get since we are relying on a C99 extension in C++ in this case, and we have -Weverything set. We get the same warning if we just use -Wpedantic , as shown here: https://godbolt.org/z/M9ahE4, indicating

CMake passes all gcc flags to nvcc as well

£可爱£侵袭症+ 提交于 2020-06-27 04:11:22
问题 My project uses cuda kernel for a small module and needs nvcc for compiling. During compilation, cmake pass the same linker and compiler flags intended for gcc to nvcc as well. In my particular case, I get the following error. nvcc fatal : Unknown option 'Wl,--no-as-needed' Following the accepted answer in this thread, I managed to remove the compiler flags for the target that needs nvcc as follows. get_target_property(_target_cxx_flags target_that_needs_nvcc COMPILE_OPTIONS) list(REMOVE_ITEM