我的Xcode 9.2可以选择使用: C++或-std=gnu++17编译-std=c++17。
我的具有一些C++特性的C++17代码编译成功。
但是,如果我试图使用相同的标志在我的终端中编译相同的代码,则会得到以下错误:
clang++ -std=c++17 test.cpp -o test error: invalid value 'c++17' in '-std=c++17'
和
clang++ -std=gnu++17 test.cpp -o test error: invalid value 'gnu++17' in '-
比方说,出于我自己的原因,我希望类有一个非静态引用成员。我认为这种类型应该很容易地从大多数使用它的代码中优化。因此,我在单元测试中断言它的琐碎性。
Clang和GCC同意这门课是微不足道的,但MSVC不同意。根据标准,谁是对的,为什么?
#include <type_traits>
struct example {
int& r;
};
// Clang and GCC let this pass
// MSVC fires this assertion
static_assert(
std::is_trivial<example>::va
是否为容器实现定义了移动构造函数noexcept属性?我刚刚发现,以下内容将在clang中起作用,但在gcc或msvc++中不起作用:
std::vector<std::vector<std::unique_ptr<int>>> vector_a;
std::vector<std::stack<std::unique_ptr<int>>> vector_b;
vector_a.reserve(10); // this works in all tested compilers
vector_b.reserve(10);
考虑以下代码:
template<typename T>
struct A { };
// same as A, but with one extra defaulted parameter
template<typename T, typename F = int>
struct B { };
template<template<typename> typename T>
T<int> build() { return {}; }
int main()
{
build<A>(); // works in
此代码在GCC 11和Clang 13 ( C++20模式)中不加警告地编译。
struct A {
int x, y;
};
struct B : A { };
int main () {
A a{1,2};
B b{3,4}; // Clang 12 wants B b{{3,4}}
return a.x * b.x + a.y * b.y;
}
但在Clang 12我们得到
<source>:10:9: warning: suggest braces around initialization of subobject [-Wmis
为了进行元编程,我想将一个成员函数指针存储在一个类型中,然后使用它来参数化一个模板。
通过类推,下面是一个工作示例,说明如何将int存储在integer_constant类型中:
template< int I >
struct integer_constant {
static constexpr int value = I;
};
template <int I>
struct A {
// (client type, probably does other things with I)
static constexpr int val
我不能用-std=c++17编译,我得到: error: invalid value 'c++17' in '-std=c++17' 然而,我更新了Xcode和clang。 我的Clang版本是: Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 9.0.0 (clang-900.0.39.2)
Target: x86_64-apple-
我在Ubuntu上使用以下命令安装了clang-tidy:
sudo apt install clang-tidy
我在一个简单的C++ 17文件上运行它,得到一个警告和错误:
/home/erelsgl/Dropbox/ariel/CPLUSPLUS/intro/01-single-file/ptr.cpp:17:3: warning: 'auto' type specifier is a C++11 extension [clang-diagnostic-c++11-extensions]
auto i = make_unique<in