我有一个C程序试图修改const字符串文字.就像现在我了解到这是不允许的.
当我用clang test.c编译器编译代码时没有给出警告.但是当我用clang++ test.c它编译它时会发出警告:
test.c:6:15:警告:不推荐将字符串文字转换为'char*'[-Wdeprecated-writable-strings] char*s ="hello world"; ^
问题是它结果clang++只是一个符号链接clang:
ll `which clang++`
lrwxr-xr-x 1 root admin 5 Jan 1 12:34 /usr/bin/clang++@ -> clang
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,如果它是符号链接,那么它的clang++行为会有clang什么不同clang?
如果是这样,我该如何开启?我自己在文档中找不到这个,谷歌没有提供有用的结果
例如,
int arr[2];
arr[5] = n; // runtime error
Run Code Online (Sandbox Code Playgroud) 我只是想改变包含搜索路径顺序(我相信).
/usr/local/include首先需要.
但由于重复,它不会改变.我该怎么改变它?
我想有默认设置,因为我没有指定的路径出现.喜欢/usr/include/c++/4.2.1,/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0/include
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" -cc1 -triple x86_64-apple-macosx10.10.0 -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name test_common.cpp -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -masm-verbose -munwind-tables -target-cpu core2 -target-linker-version 241.9 -v -gdwarf-2 -coverage-file /Users/machidahiroaki/RubymineProjects/caffe/.build_debug/src/caffe/test/test_common.o -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.0 -D DEBUG -D CPU_ONLY -I /usr/local/include -I /usr/local/include -I /Users/machidahiroaki/anaconda/include -I /Users/machidahiroaki/anaconda/include/python2.7 -I /Users/machidahiroaki/anaconda/lib/python2.7/site-packages/numpy/core/include -I .build_debug/src -I ./src -I ./include -I /usr/local/atlas/include -stdlib=libstdc++ -O0 -Wall -Wno-sign-compare -Wno-unneeded-internal-declaration -fdeprecated-macro -fdebug-compilation-dir /Users/machidahiroaki/RubymineProjects/caffe -ferror-limit 19 -fmessage-length 0 -pthread -stack-protector 1 -mstackrealign -fblocks -fobjc-runtime=macosx-10.10.0 -fencode-extended-block-signature -fcxx-exceptions -fexceptions -fdiagnostics-show-option …Run Code Online (Sandbox Code Playgroud) 考虑这个代码示例:
#include <initializer_list>
#include <iostream>
int main()
{
for(auto e: []()->std::initializer_list<int>{return{1,2,3};}())
std::cout<<e<<std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我尝试用g ++编译它(gcc版本4.9.2(Debian 4.9.2-10)),输出正确.在clang ++中(Debian clang版本3.5.0-9(标签/ RELEASE_350/final)(基于LLVM 3.5.0))输出例如:
0
2125673120
32546
Run Code Online (Sandbox Code Playgroud)
第一行总是0,最后两行是"随机".
这是clang或其他什么的错误?我认为这个代码示例是正确的.
更新:
当lambda函数返回类型是别的东西(例如std :: vector或std :: array)时,这段代码工作正常.
我正在尝试将Google的Address Sanitizer与CUDA项目结合使用,更准确地说是使用OpenCV cuda功能.但是我在第一次cuda电话上遇到了"内存不足"的错误.
OpenCV Error: Gpu API call (out of memory) in getDevice, file opencv-2.4.11/src/opencv-2.4.11/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp, line 664
terminate called after throwing an instance of 'cv::Exception'
what(): opencv-2.4.11/src/opencv-2.4.11/modules/dynamicuda/include/opencv2/dynamicuda/dynamicuda.hpp:664: error: (-217) out of memory in function getDevice
Run Code Online (Sandbox Code Playgroud)
它可以复制
#include <opencv2/gpu/gpu.hpp>
int main()
{
cv::gpu::printCudaDeviceInfo(cv::gpu::getDevice());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
用.编译
clang++ -fsanitize=address -lstdc++ -lopencv_gpu -lopencv_core -o sanitizer sanitizer.cpp && LD_LIBRARY_PATH=/usr/local/lib ./sanitizer
Run Code Online (Sandbox Code Playgroud)
我用gcc得到了同样的结果.我也尝试过将cuda函数列入黑名单而没有结果.
现在使用没有opencv的cuda:
#include <cuda_runtime.h>
int main()
{
int count = -1;
cudaGetDevice(&count);
cout << "Device count: " << count << endl; …Run Code Online (Sandbox Code Playgroud) 考虑以下计划:
struct S {
using T = float;
operator T() { return 9.9f; }
};
int main() {
S m;
S::T t = m;
t = m.operator T(); // Is this correct ?
}
Run Code Online (Sandbox Code Playgroud)
该程序在g ++中编译良好(请参阅此处的实时演示)
但它在clang ++,MSVC++和Intel C++编译器的编译中失败了
clang ++给出以下错误(请参阅此处的在线演示)
main.cpp:8:20: error: unknown type name 'T'; did you mean 'S::T'?
t = m.operator T(); // Is this correct ?
^
S::T
main.cpp:2:11: note: 'S::T' declared here
using T = float;
Run Code Online (Sandbox Code Playgroud)
MSVC++给出以下错误(请参阅此处的实时演示)
source_file.cpp(8): error …Run Code Online (Sandbox Code Playgroud) 亲爱的Assembly/C++ dev,
问题是:传播两个ASM块之间的进位(或任何标志)是现实的还是完全疯狂的,即使它有效?
几年前,我为低于512位的大型算术开发了一个整数库(在编译时).我此时没有使用GMP,因为对于这种规模,GMP由于内存分配而变慢,并且模型选择二进制表示工作台.
我必须承认我创建了我的ASM(字符串块)使用BOOST_PP,它不是非常光荣(好奇的看看它vli).图书馆运作良好.
但是我注意到,此时不可能在两个ASM内联块之间传播状态寄存器的进位标志.这是合乎逻辑的,因为对于编译器在两个块之间生成的任何助记符,寄存器被复位(mov指令除外(来自我的汇编知识)).
昨天我有一个想法,传播两个ASM块之间的进位有点棘手(使用递归算法).它工作,但我认为我很幸运.
#include <iostream>
#include <array>
#include <cassert>
#include <algorithm>
//forward declaration
template<std::size_t NumBits>
struct integer;
//helper using object function, partial specialization is forbiden on functions
template <std::size_t NumBits, std::size_t W, bool K = W == integer<NumBits>::numwords>
struct helper {
static inline void add(integer<NumBits> &a, const integer<NumBits> &b){
helper<NumBits, integer<NumBits>::numwords>::add(a,b);
}
};
// first addition (call first)
template<std::size_t NumBits, std::size_t W>
struct helper<NumBits, W, 1> {
static …Run Code Online (Sandbox Code Playgroud) 我注意到Clang和GCC之间的行为有以下代码:
class convertible {
public:
operator int() { return 1; }
template <typename T>
operator T() { return 1; }
};
int main () {
convertible x;
switch (x) {} // Clang: OK GCC: Compile error
return 0;
}
Run Code Online (Sandbox Code Playgroud)
GCC回归 error: default type conversion can't deduce template argument for ‘template<class T> convertible::operator T()’
Clang编译代码没有错误和调用 operator int()
我正在使用Clang 6和GCC 8.两者都使用std = c ++ 11
在这种情况下哪个编译器是正确的?
GCC和clang对此代码持不同意见.
#include <type_traits>
template <typename T, template <typename...> typename Tpl>
struct storage {
using type_t = T;
template <typename... Args>
using storage_tpl = Tpl<Args...>;
};
template <typename T, template <typename...> typename>
struct F{
constexpr static int x = 1;
};
template <typename T >
struct F<T, std::void_t>{
constexpr static int x = 2;
};
int f() {
using S = storage<int, std::void_t>;
static_assert(F<int, S::storage_tpl>().x == 2);
return F<int, S::storage_tpl>().x;
}
Run Code Online (Sandbox Code Playgroud)
根据铿锵S::storage_tpl不是std::void_t; 结果,它选择主模板F而不是部分特化,从而选择断言.
乍一看,它看起来像GCC是正确的,因为它知道该嵌套模板仅仅是一个别名std::void_t,但也许是太聪明,该标准要求S::storage_tpl …
使用编译此代码时-Warray-bounds。声明array2时收到警告array index 3 is past the end of the array (which contains 3 elements)。但是,在声明array1时,即使它必须是相同的类型,从而携带相同的大小信息,也并非如此。这是c中的错误吗?
enum class Format : int {
Off = 55,
FormatA = 66,
FormatB = 77,
};
inline Format (&AllFormats())[3] {
static Format values[] = {
Format::Off,
Format::FormatA,
Format::FormatB
};
return values;
}
int main()
{
auto array1 = AllFormats();
auto v3 = array1[3];
Format (&array2)[3] = AllFormats();
v3 = array2[3];
}
Run Code Online (Sandbox Code Playgroud)