草庐IT

c++ - 使用 Clang 的函数原型(prototype)中不允许使用“自动”

使用带有std=c++1y标志的Clang3.5、3.6或3.7,以下代码无法编译:#includeautofoo(autobar){returnbar;}intmain(){std::cout给出的错误是:error:'auto'notallowedinfunctionprototype我在使用g++4.9时没有错误。产生此错误是因为Clang尚未实现此功能,还是因为我不允许这样做而GCC以某种方式允许它? 最佳答案 正如我们从ISOC++讨论邮件中看到的:decltype(auto)parametersvs.perfectfor

c++ - 如何在 -std=c++11 -Weverything -Werror 中使用 clang++

我要编译以下文件(temp.cpp):#includeclassFoo{public:Foo()=default;};intmain(){std::cout使用以下命令:clang++temp.cpp-otemp-std=c++11-Weverything-Werror有一个错误:temp.cpp:5:11:error:defaultedfunctiondefinitionsareincompatiblewithC++98[-Werror,-Wc++98-compat]我知道有一个像c++98-compat这样的警告,它是一切的一部分。如何启用除c++98-compat之外的所有警告?

c++ - 如何在 -std=c++11 -Weverything -Werror 中使用 clang++

我要编译以下文件(temp.cpp):#includeclassFoo{public:Foo()=default;};intmain(){std::cout使用以下命令:clang++temp.cpp-otemp-std=c++11-Weverything-Werror有一个错误:temp.cpp:5:11:error:defaultedfunctiondefinitionsareincompatiblewithC++98[-Werror,-Wc++98-compat]我知道有一个像c++98-compat这样的警告,它是一切的一部分。如何启用除c++98-compat之外的所有警告?

c++ - std::shared_ptr 和初始化列表

std::shared_ptr构造函数的行为不符合我的预期:#include#includevoidfunc(std::vectorstrings){for(autoconst&string:strings){std::coutstrings){for(auto&string:strings){std::cout({"foo","bar","baz"});//won'tcompile.//autoptr=std::make_shared{"foo","bar","baz"};//northis.return0;}我做错了什么还是编译器?编译器是:$clang++--versionApp

c++ - std::shared_ptr 和初始化列表

std::shared_ptr构造函数的行为不符合我的预期:#include#includevoidfunc(std::vectorstrings){for(autoconst&string:strings){std::coutstrings){for(auto&string:strings){std::cout({"foo","bar","baz"});//won'tcompile.//autoptr=std::make_shared{"foo","bar","baz"};//northis.return0;}我做错了什么还是编译器?编译器是:$clang++--versionApp

c++ - 模板替换和 SFINAE 中的私有(private)成员访问

classA{inta;};templateclasstest{};templateclasstest{};intmain(){testa;}上面的代码在clangversion3.8.0-2ubuntu4(tags/RELEASE_380/final)上编译没有错误,但无法在g++-5(Ubuntu5.4.1-2ubuntu1~16.04)5.4.120160904上编译和g++-6(Ubuntu6.2.0-3ubuntu11~16.04)6.2.020160901有这样的错误:main.cpp:Infunction‘intmain()’:main.cpp:9:22:error:‘i

c++ - 模板替换和 SFINAE 中的私有(private)成员访问

classA{inta;};templateclasstest{};templateclasstest{};intmain(){testa;}上面的代码在clangversion3.8.0-2ubuntu4(tags/RELEASE_380/final)上编译没有错误,但无法在g++-5(Ubuntu5.4.1-2ubuntu1~16.04)5.4.120160904上编译和g++-6(Ubuntu6.2.0-3ubuntu11~16.04)6.2.020160901有这样的错误:main.cpp:Infunction‘intmain()’:main.cpp:9:22:error:‘i

c++ - 可变参数模板模板参数可以部分特化吗?

考虑以下程序:templateclass>structfoo{};templateclassC>structfoo{};intmain(){}Clang以错误方式拒绝它:classtemplatepartialspecializationdoesnotspecializeanytemplateargument即使在最新的clang7.0HEAD中,参见演示here.但是,gccacceptsit.请参阅[temp.class.spec]在说明部分特化规则的地方,我找不到任何禁止该模板部分特化的内容。特别是特化确实是morespecialized,错误信息看起来不正确。编辑:但是,gcc

c++ - 可变参数模板模板参数可以部分特化吗?

考虑以下程序:templateclass>structfoo{};templateclassC>structfoo{};intmain(){}Clang以错误方式拒绝它:classtemplatepartialspecializationdoesnotspecializeanytemplateargument即使在最新的clang7.0HEAD中,参见演示here.但是,gccacceptsit.请参阅[temp.class.spec]在说明部分特化规则的地方,我找不到任何禁止该模板部分特化的内容。特别是特化确实是morespecialized,错误信息看起来不正确。编辑:但是,gcc

c++ - 默认情况下,clang 中是否有一组已知的 `c++11` 功能不需要 `-std=c++11` ?

clang(3.4)似乎自动接受某些c++11(例如auto、for(:))而没有特殊标志(尽管产生警告),但不接受其他部分(例如lambdas).例如下面编译clang++c++11.success.cpp:#includeintmain(intargCount,char**argVec){std::vectorvec;for(auto&item:vec){++item;}return0;}但这失败了clang++c++11.failure.cpp:#includeintmain(intargCount,char**argVec){std::vectorvec;autolambda=