c++17

Does struct with reference member have unique object representation?

爱⌒轻易说出口 提交于 2020-07-05 05:28:53
问题 This answer raised the following question. Suppose we have a simple struct S { int& i; } Internally (in GCC and Clang, at least) S contains just a pointer to an int , and static_assert(sizeof(int*) == 8); static_assert(sizeof(S) == 8); Does S have a unique object representation? GCC and Clang disagree *: static_assert( std::has_unique_object_representations_v<int*>); static_assert(!std::has_unique_object_representations_v<S>); // GCC static_assert( std::has_unique_object_representations_v<S>)

Does struct with reference member have unique object representation?

筅森魡賤 提交于 2020-07-05 05:26:31
问题 This answer raised the following question. Suppose we have a simple struct S { int& i; } Internally (in GCC and Clang, at least) S contains just a pointer to an int , and static_assert(sizeof(int*) == 8); static_assert(sizeof(S) == 8); Does S have a unique object representation? GCC and Clang disagree *: static_assert( std::has_unique_object_representations_v<int*>); static_assert(!std::has_unique_object_representations_v<S>); // GCC static_assert( std::has_unique_object_representations_v<S>)

emplace_back causes link error on static constexpr member

ⅰ亾dé卋堺 提交于 2020-07-03 05:50:39
问题 Why does emplace_back take a reference of the member that requires a definition? What is the difference between emplace_back(integer literal) and emplace_back(static constexpr integer member) ? If I switch to C++17, it compiles fine. I found that in C++17 static constexpr data members are implicitly inlined. Does it mean the compiler implicitly creates a definition for them? Example code: class base { int n; public: base(int n):n(n) {} }; struct base_trait { static constexpr int n = 1; }; int

How to avoid std::filesystem linker errors with Qt?

你离开我真会死。 提交于 2020-06-28 03:07:35
问题 I would like to use the std::filesystem with Qt 5.12.0 with the g++ version Ubuntu 8.2.0-7ubuntu1, but getting linker errors: g++ -lstdc++fs -Wl,-rpath,/home/user/Qt/5.12.0/gcc_64/lib -o qf_filesystem_test main.o -L/home/user/Qt/5.12.0/gcc_64/lib -lQt5Widgets -lQt5Gui -lQt5Core -lGL -lpthread /usr/bin/ld: main.o: in function `std::filesystem::exists(std::filesystem::__cxx11::path const&)': /usr/include/c++/8/bits/fs_ops.h:121: undefined reference to `std::filesystem::status(std::filesystem::_

Non-overloadable non-inline function definitions in different translation units

落爺英雄遲暮 提交于 2020-06-27 11:35:10
问题 Let's say I have 2 TUs with 2 non-inline function definitions with external linkage which differ only in their return types. Which paragraph(s) my program violates? [basic.def.odr]/4 says: Every program shall contain exactly one definition of every non-inline function or variable that is odr-used in that program outside of a discarded statement; no diagnostic required. But This paragraph says "that is odr-used" which may or may not be the case. How do I tell if I define the same non-inline

Clang can't find template binary operator in fold expression

时光怂恿深爱的人放手 提交于 2020-06-27 09:49:13
问题 This is my binary operator to concatenate tuples: template <class... Args1, class... Args2> constexpr decltype(auto) operator+(const std::tuple<Args1...> &tup1, const std::tuple<Args2...> &tup2) { return std::tuple_cat(tup1, tup2); } It works perfectly on both compiler (gcc, clang) with two tuples: template <class Arg1, class Arg2> constexpr decltype(auto) concat_test(Arg1 &&arg1, Arg2 &&arg2) { return arg1 + arg2; } But when I try to use it in fold expression like follows: template <class...

Clang can't find template binary operator in fold expression

房东的猫 提交于 2020-06-27 09:49:05
问题 This is my binary operator to concatenate tuples: template <class... Args1, class... Args2> constexpr decltype(auto) operator+(const std::tuple<Args1...> &tup1, const std::tuple<Args2...> &tup2) { return std::tuple_cat(tup1, tup2); } It works perfectly on both compiler (gcc, clang) with two tuples: template <class Arg1, class Arg2> constexpr decltype(auto) concat_test(Arg1 &&arg1, Arg2 &&arg2) { return arg1 + arg2; } But when I try to use it in fold expression like follows: template <class...

To move, or not to move from r-value ref-qualified method?

 ̄綄美尐妖づ 提交于 2020-06-27 06:48:06
问题 In the following C++11+ code which return statement construction should be preferred? #include <utility> struct Bar { }; struct Foo { Bar bar; Bar get() && { return std::move(bar); // 1 return bar; // 2 } }; 回答1: Well, since it's a r-value ref qualified member function, this is presumably about to expire. So it makes sense to move bar out, assuming Bar actually gains something from being moved. Since bar is a member, and not a local object/function parameter, the usual criteria for copy

Is it a defect in the standard about dependent name resolution for template

怎甘沉沦 提交于 2020-06-26 13:59:41
问题 About how lookup the dependent name for template, The standard only gives a little sentence like this, there's no more: In resolving dependent names, names from the following sources are considered: Declarations that are visible at the point of definition of the template . Declarations from namespaces associated with the types of the function arguments both from the instantiation context ([temp.point]) and from the definition context. Consider the below code struct Test{ using type = int; };

Why does code with std::vector not compile but with std::unique_ptr it does, if there is no noexcept move constructor?

依然范特西╮ 提交于 2020-06-25 21:48:07
问题 Why can the following program not be compiled? NB: something_t's move constructor is not noexcept. #include <memory> #include <vector> class something_t { public: constexpr something_t() = default; constexpr something_t(const something_t& other) : field_(other.field_) { } constexpr something_t(something_t&& other) : field_(other.field_) { } private: unsigned int field_{ 0 }; }; struct data_t { something_t something; std::vector<std::unique_ptr<int>> move_only; // <-- this line }; int main() {