language-lawyer

Reusing data member storage via placement new during enclosing object's lifetime

佐手、 提交于 2019-12-18 18:09:18
问题 This bounty has ended . Answers to this question are eligible for a +100 reputation bounty. Bounty grace period ends in 15 hours . walnut is looking for an answer from a reputable source . This is a follow-up to my previous question where I seem to have made the problem more involved than I had originally intended. (See discussions in question and answer comments there.) This question is a slight modification of the original question removing the issue of special rules during construction

Reusing data member storage via placement new during enclosing object's lifetime

三世轮回 提交于 2019-12-18 18:09:12
问题 This bounty has ended . Answers to this question are eligible for a +100 reputation bounty. Bounty grace period ends in 15 hours . walnut is looking for an answer from a reputable source . This is a follow-up to my previous question where I seem to have made the problem more involved than I had originally intended. (See discussions in question and answer comments there.) This question is a slight modification of the original question removing the issue of special rules during construction

MSVC error when using capture-less lambda expressions as second and third operand of conditional operator

北慕城南 提交于 2019-12-18 17:26:33
问题 The code below is happily accepted by both GCC and Clang with -std=c++14 but causes a compile error with Visual Studio 2013. #include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { auto increasing = [](int lhs, int rhs){return lhs < rhs;}; auto decreasing = [](int lhs, int rhs){return lhs > rhs;}; std::vector<int> v(0, 10); bool increase = true; std::sort(v.begin(), v.end(), increase ? increasing : decreasing); return 0; } The error is: main.cpp(11): error

MSVC error when using capture-less lambda expressions as second and third operand of conditional operator

一曲冷凌霜 提交于 2019-12-18 17:26:04
问题 The code below is happily accepted by both GCC and Clang with -std=c++14 but causes a compile error with Visual Studio 2013. #include <iostream> #include <algorithm> #include <vector> using namespace std; int main() { auto increasing = [](int lhs, int rhs){return lhs < rhs;}; auto decreasing = [](int lhs, int rhs){return lhs > rhs;}; std::vector<int> v(0, 10); bool increase = true; std::sort(v.begin(), v.end(), increase ? increasing : decreasing); return 0; } The error is: main.cpp(11): error

Is the behaviour of the compiler undefined, with Undefined Behaviour?

折月煮酒 提交于 2019-12-18 17:04:53
问题 When I answered this question, I wrote: First, it is important to note that it is not only the behaviour of the user program that is undefined, it is the behaviour of the compiler that is undefined. But there was disagreement in a comment, so I want to ask the question here: If the source code contains Undefined Behaviour, is it only the behaviour of the translated machine code that is undefined, or is the behaviour of the compiler undefined, too? The standard defines the behaviour of an

Visual Studio 2015 - Compiler Warning (level 2) C4146

微笑、不失礼 提交于 2019-12-18 16:32:16
问题 I have the following line in my code signed int test_case= -2147483648; which generates the error: C4146 unary minus operator applied to unsigned type, result still unsigned but this is still with the data range of teh signed integer type: __int32 signed, signed int, int –2,147,483,648 to 2,147,483,647 The strange things is assigning it as signed long gives this same error, i.e. signed long test_case= -2147483648; The changes below compile OK: signed int test_case= -2147483647; signed int

Maybe my understanding of [class.access]/7 isn't correct, but

社会主义新天地 提交于 2019-12-18 15:17:10
问题 From [class.access]/7 we have the following sentence: Similarly, the use of A::B as a base-specifier is well-formed because D is derived from A , so checking of base-specifier s must be deferred until the entire base-specifier-list has been seen. class A { protected: struct B { }; }; struct D: A::B, A { }; See live example with clang. As a matter of fact, clang also complains about this snippet, where no deferment is necessary. class A { protected: struct B { }; }; struct D: A, A::B { }; Why

Overloading structs with template call operator and generic lambdas - gcc vs clang

若如初见. 提交于 2019-12-18 15:08:19
问题 I have discovered a code snippet that compiles and works properly in clang++ 4 (and trunk) but fails to compile in g++ 7 (and trunk) . Let's assume I have the following struct types: struct a { void foo() { } }; struct b { void bar() { } }; struct c { void bar() { } }; I want to create an overload set out of lambdas which handles a explicitly, while b and c are "caught" with a generic lambda using an auto parameter: auto ol = overload([](a x) { x.foo(); }, [](auto x){ x.bar(); }) When I

Injected-class-names of class templates

空扰寡人 提交于 2019-12-18 14:46:46
问题 Inspired by the code in this answer. Consider: template<class> class A { }; int main() { A<float> a(A<float>::A<int>()); return 0; } Is this code ill-formed, because A<float>::A names the constructor (per §3.4.3.1 [class.qual]/p2) and cannot be used in this context (plus the <int> would complete fail to parse anyway), or well-formed, with A<float>::A being the injected-class-name , used as a template-name (§14.6.1 [temp.local]), such that A<float>::A<int> means exactly the same as A<int> ,

Value initialization: default initialization or zero initialization?

天大地大妈咪最大 提交于 2019-12-18 14:14:46
问题 I have templated gray_code class which is meant to store some unsigned integer whose underlying bits are stored in Gray code order. Here it is: template<typename UnsignedInt> struct gray_code { static_assert(std::is_unsigned<UnsignedInt>::value, "gray code only supports built-in unsigned integers"); // Variable containing the gray code UnsignedInt value; // Default constructor constexpr gray_code() = default; // Construction from UnsignedInt constexpr explicit gray_code(UnsignedInt value):