c++17

clang c++17 std::vector over aligned types copy of elements SIGSEGV when compiled with -mavx

半世苍凉 提交于 2021-01-26 23:28:13
问题 According to this question I thought that in C++17 a std::vector with default allocator should handle over aligned types. However, the following code #include <iostream> #include <iterator> #include <array> #include <vector> template<typename T, size_t N, size_t Alignment> struct alignas(Alignment) AlignedArray : public std::array<T, N> { friend std::ostream& operator<<(std::ostream& o, const AlignedArray& a) { std::copy(a.cbegin(), a.cend(), std::ostream_iterator<T>(o, " ")); return o; } };

clang c++17 std::vector over aligned types copy of elements SIGSEGV when compiled with -mavx

为君一笑 提交于 2021-01-26 23:27:29
问题 According to this question I thought that in C++17 a std::vector with default allocator should handle over aligned types. However, the following code #include <iostream> #include <iterator> #include <array> #include <vector> template<typename T, size_t N, size_t Alignment> struct alignas(Alignment) AlignedArray : public std::array<T, N> { friend std::ostream& operator<<(std::ostream& o, const AlignedArray& a) { std::copy(a.cbegin(), a.cend(), std::ostream_iterator<T>(o, " ")); return o; } };

[[maybe_unused]] on member variable, GCC warns (incorrectly?) that attribute is ignored

落爺英雄遲暮 提交于 2021-01-26 22:51:20
问题 In the following example: struct Foo { [[maybe_unused]] int member = 1; void bar() { [[maybe_unused]] int local = 0; } }; int main(int argc, char* argv[]) { Foo f{}; f.bar(); return 0; } GCC emits a warning where Clang and MSVC do not: warning: 'maybe_unused' attribute ignored [-Wattributes] [[maybe_unused]] int member = 1; As far as I can tell, this should be legal (and not ignored by the compiler). According to the standard: 10.6.7 Maybe unused attribute [dcl.attr.unused] ... 2. The

[[maybe_unused]] on member variable, GCC warns (incorrectly?) that attribute is ignored

自闭症网瘾萝莉.ら 提交于 2021-01-26 22:50:10
问题 In the following example: struct Foo { [[maybe_unused]] int member = 1; void bar() { [[maybe_unused]] int local = 0; } }; int main(int argc, char* argv[]) { Foo f{}; f.bar(); return 0; } GCC emits a warning where Clang and MSVC do not: warning: 'maybe_unused' attribute ignored [-Wattributes] [[maybe_unused]] int member = 1; As far as I can tell, this should be legal (and not ignored by the compiler). According to the standard: 10.6.7 Maybe unused attribute [dcl.attr.unused] ... 2. The

[[maybe_unused]] on member variable, GCC warns (incorrectly?) that attribute is ignored

不打扰是莪最后的温柔 提交于 2021-01-26 22:49:29
问题 In the following example: struct Foo { [[maybe_unused]] int member = 1; void bar() { [[maybe_unused]] int local = 0; } }; int main(int argc, char* argv[]) { Foo f{}; f.bar(); return 0; } GCC emits a warning where Clang and MSVC do not: warning: 'maybe_unused' attribute ignored [-Wattributes] [[maybe_unused]] int member = 1; As far as I can tell, this should be legal (and not ignored by the compiler). According to the standard: 10.6.7 Maybe unused attribute [dcl.attr.unused] ... 2. The

typeid(“”) != typeid(const char*)

狂风中的少年 提交于 2021-01-26 19:25:42
问题 I'm making a C++ library which relies heavily on RTTI (customizable bridge to another language) and is very confused about string literal type. This is a simple test I made to show the problem: std::cout << typeid(const char*).name() << std::endl; // PKc std::cout << std::any("").type().name() << std::endl; // PKc std::cout << typeid("").name() << std::endl; // A1_c For me it looks like the first two print the type for const char* , but the last one is an array. Why do results for std::any(""

typeid(“”) != typeid(const char*)

笑着哭i 提交于 2021-01-26 19:25:18
问题 I'm making a C++ library which relies heavily on RTTI (customizable bridge to another language) and is very confused about string literal type. This is a simple test I made to show the problem: std::cout << typeid(const char*).name() << std::endl; // PKc std::cout << std::any("").type().name() << std::endl; // PKc std::cout << typeid("").name() << std::endl; // A1_c For me it looks like the first two print the type for const char* , but the last one is an array. Why do results for std::any(""

What's the difference between a sentinel and an end iterator?

这一生的挚爱 提交于 2021-01-21 12:19:08
问题 While reading Eric Niebler's range proposal, I've come across the term sentinel as replacement for the end iterator. I'm having a difficult time understanding the benefits of sentinel over an end iterator. Could someone provide a clear example of what sentintel brings to the table that cannot be done with standard iterator pairs? "A sentinel is an abstraction of a past-the-end iterator. Sentinels are Regular types that can be used to denote the end of a range. A sentinel and an iterator

Why does as_const forbid rvalue arguments?

你离开我真会死。 提交于 2021-01-21 12:15:08
问题 I wanted to ask why as_const forbids rvalue arguments, according to cppreference.com (i.e. why the Standards folks made it so, not why cppreference.com specifically quoted them on that. And also not where in the spec the intent of the committee is codified, just for making sure :))). This (artificial) example would yield an error (user wants to make it const to keep COW quiet) QChar c = as_const(getQString())[0]; Another question's answer notes that if we just remove the deletion of the

Why does as_const forbid rvalue arguments?

纵饮孤独 提交于 2021-01-21 12:13:30
问题 I wanted to ask why as_const forbids rvalue arguments, according to cppreference.com (i.e. why the Standards folks made it so, not why cppreference.com specifically quoted them on that. And also not where in the spec the intent of the committee is codified, just for making sure :))). This (artificial) example would yield an error (user wants to make it const to keep COW quiet) QChar c = as_const(getQString())[0]; Another question's answer notes that if we just remove the deletion of the