草庐IT

iphoneos-clang

全部标签

c++ - 在多线程环境中使用 std::string 时 Clang 的线程清理器警告

在使用clang的线程清理器时,我们注意到数据竞争警告。我们认为这是由于std::string的写时复制技术不是线程安全的,但我们可能错了。我们将看到的警告减少到此代码:voidtest3(){std::unique_ptrthread;{autooutput=make_shared();std::stringstr="test";thread.reset(newstd::thread([str,output](){*output+=str;}));//ThestrstringnowgoesoutofscopebutduetoCOW//thecapturedstringmaynotha

c++ - 在多线程环境中使用 std::string 时 Clang 的线程清理器警告

在使用clang的线程清理器时,我们注意到数据竞争警告。我们认为这是由于std::string的写时复制技术不是线程安全的,但我们可能错了。我们将看到的警告减少到此代码:voidtest3(){std::unique_ptrthread;{autooutput=make_shared();std::stringstr="test";thread.reset(newstd::thread([str,output](){*output+=str;}));//ThestrstringnowgoesoutofscopebutduetoCOW//thecapturedstringmaynotha

c++ - 在 B 类中声明为友元的 A 类成员模板函数无法访问 A 类的私有(private)成员(仅限 Clang)

请查看此代码段。我知道这没有多大意义,只是为了说明我遇到的问题:#includeusingnamespacestd;structtBar{templatevoidPrintDataAndAddress(constT&thing){cout(thing);}private://friendstructtFoo;//fixesthecompilationerrortemplatevoidPrintAddress(constT&thing){cout(consttFoo&);private:intmData=42;};structtWidget{intmData=666;};intmain(

c++ - 在 B 类中声明为友元的 A 类成员模板函数无法访问 A 类的私有(private)成员(仅限 Clang)

请查看此代码段。我知道这没有多大意义,只是为了说明我遇到的问题:#includeusingnamespacestd;structtBar{templatevoidPrintDataAndAddress(constT&thing){cout(thing);}private://friendstructtFoo;//fixesthecompilationerrortemplatevoidPrintAddress(constT&thing){cout(consttFoo&);private:intmData=42;};structtWidget{intmData=666;};intmain(

c++ - 在 clang++ 中使用 boost/thread header 时遇到问题 (Windows)

我正在尝试使用clang++在Windows上使用Boost.Thread。在包含boost/thread.hpp时,我收到以下编译错误:使用-DBOOST_USE_WINDOWS_H:InfileincludedfromD:/env/boost/boost_1_58_0\boost/thread.hpp:13:InfileincludedfromD:/env/boost/boost_1_58_0\boost/thread/thread.hpp:12:InfileincludedfromD:/env/boost/boost_1_58_0\boost/thread/thread_only

c++ - 在 clang++ 中使用 boost/thread header 时遇到问题 (Windows)

我正在尝试使用clang++在Windows上使用Boost.Thread。在包含boost/thread.hpp时,我收到以下编译错误:使用-DBOOST_USE_WINDOWS_H:InfileincludedfromD:/env/boost/boost_1_58_0\boost/thread.hpp:13:InfileincludedfromD:/env/boost/boost_1_58_0\boost/thread/thread.hpp:12:InfileincludedfromD:/env/boost/boost_1_58_0\boost/thread/thread_only

c++ - clang 5:std::optional 实例化参数类型的 std::is_constructible 特征

当切换到c++17并用标准解决方案替换自定义std::optional解决方案时,检测到clang5的一个非常奇怪和意外的行为。出于某种原因,由于对参数类的std::is_constructible特征的错误评估,emplace()被禁用。在复制之前必须满足一些特定的先决条件:#include///Precondition#1:TmustbeanestedstructstructFoo{structVictim{///Precondition#2:Tmusthaveanaggregate-initializer///foroneofitsmembersstd::size_tvalue{

c++ - clang 5:std::optional 实例化参数类型的 std::is_constructible 特征

当切换到c++17并用标准解决方案替换自定义std::optional解决方案时,检测到clang5的一个非常奇怪和意外的行为。出于某种原因,由于对参数类的std::is_constructible特征的错误评估,emplace()被禁用。在复制之前必须满足一些特定的先决条件:#include///Precondition#1:TmustbeanestedstructstructFoo{structVictim{///Precondition#2:Tmusthaveanaggregate-initializer///foroneofitsmembersstd::size_tvalue{

c++ - 为什么 move 构造函数既没有用clang声明也没有删除?

考虑以下类。structwith_copy{with_copy()=default;with_copy(with_copyconst&){}with_copy&operator=(with_copyconst&){return*this;}};structfoo{with_copyc;std::unique_ptrp;};with_copy有复制构造函数吗?是的。它是明确定义的。with_copy是否有move构造函数?不会。显式复制构造函数会阻止生成它。with_copy是否有已删除的move构造函数?不,没有move构造函数与删除构造函数不同。已删除的move构造函数会尝试move

c++ - 为什么 move 构造函数既没有用clang声明也没有删除?

考虑以下类。structwith_copy{with_copy()=default;with_copy(with_copyconst&){}with_copy&operator=(with_copyconst&){return*this;}};structfoo{with_copyc;std::unique_ptrp;};with_copy有复制构造函数吗?是的。它是明确定义的。with_copy是否有move构造函数?不会。显式复制构造函数会阻止生成它。with_copy是否有已删除的move构造函数?不,没有move构造函数与删除构造函数不同。已删除的move构造函数会尝试move