language-lawyer

which is the full-expression when the rule says the full-expression of initialization

流过昼夜 提交于 2020-07-20 23:43:02
问题 struct S { constexpr S(int i): I(i),D(i) { } // full-expressions are initialization of I and initialization of D private: int I; int D; }; int main(){ constexpr S s1 = 1; //full-expression comprises call of S​::​S(int) } According to the definition of full-expression: A full-expression is an unevaluated operand, a constant-expression, an init-declarator or a mem-initializer, including the constituent expressions of the initializer, an invocation of a destructor generated at the end of the

which is the full-expression when the rule says the full-expression of initialization

白昼怎懂夜的黑 提交于 2020-07-20 23:42:25
问题 struct S { constexpr S(int i): I(i),D(i) { } // full-expressions are initialization of I and initialization of D private: int I; int D; }; int main(){ constexpr S s1 = 1; //full-expression comprises call of S​::​S(int) } According to the definition of full-expression: A full-expression is an unevaluated operand, a constant-expression, an init-declarator or a mem-initializer, including the constituent expressions of the initializer, an invocation of a destructor generated at the end of the

What does a star (asterisk) do in f-string?

南笙酒味 提交于 2020-07-20 06:48:50
问题 In the python document 2.4.3. Formatted string literals, it seems possible to write a star followed by an expression in a f-string's {} , but I cannot find how to use that. What's that and how I can use it? Is it documented somewhere? To be exact, this is regarding "*" or_expr part of the following BNF. f_string ::= (literal_char | "{{" | "}}" | replacement_field)* replacement_field ::= "{" f_expression ["!" conversion] [":" format_spec] "}" f_expression ::= (conditional_expression | "*" or

Can a std::function's target callable legally destroy the std::function during execution?

你说的曾经没有我的故事 提交于 2020-07-18 12:50:11
问题 In comments under another question, it was stated that a common mistake is to: invoke std::function when calling it leads to destruction of object which holds it While clearly a "dangerous" thing to do that would be avoided in robust code, is it actually wrong? I cannot find any wording in the standard that ensures: A std::function must not be destroyed by its target callable A std::function 's lifetime must not end during execution of its target callable The lifetime of a functor in general

where's the point of instantiation of static data member template specialization

不打扰是莪最后的温柔 提交于 2020-07-18 10:18:15
问题 Consider the below code: #include <iostream> template<typename T> struct Test{ template<typename U> static U value; }; template<typename T> template<typename U> U Test<T>::value = U{}; //#1 int main(){ auto d = Test<int>::value<int>; } //#2 The [temp.point] section in the standard covers the most case of where the point of instantiation shall place. However I think it's unclear about static data member template, due to: temp.point#1 For a function template specialization, a member function

Can “T t = {};” and “T t{};” produce different results?

谁说胖子不能爱 提交于 2020-07-17 07:39:10
问题 The question is simple. Is it possible to construct such a type T, for which the following two variables declarations will produce different results? T t1 = {}; T t2{}; I've been digging through the cppreference and the standard for more than an hour now, and I understood the following: T t2{}; is a value initialization. No surprises here. T t1 = {} is a list initialization with an empty braced-init-list. But the last one is tricky since the "effects of list initialization" is an impressive..

Does the C# compiler get the Color Color rule wrong with const type members?

谁都会走 提交于 2020-07-16 17:41:14
问题 Okay, so the C# Language Specification has a special section (old version linked) on the Color Color rule where a member and its type has the same name. Well-known guru Eric Lippert once blogged about it. The question I am going to ask here is in a sense (not) quite the same that was asked in the thread Circular definition in a constant enum. You can go and upvote that other question if you like. Now for my question. Consider this code: namespace N { public enum Color { Green, Brown, Purple,

Pure Functions: Does “No Side Effects” Imply “Always Same Output, Given Same Input”?

ぐ巨炮叔叔 提交于 2020-07-16 16:17:57
问题 The two conditions that define a function as pure are as follows: No side effects (i.e. only changes to local scope are allowed) Always return the same output, given the same input If the first condition is always true, are there any times the second condition is not true? I.e. is it really only necessary with the first condition? 回答1: Here are a few counterexamples that do not change the outer scope but are still considered impure: function a() { return Date.now(); } function b() { return

Pure Functions: Does “No Side Effects” Imply “Always Same Output, Given Same Input”?

笑着哭i 提交于 2020-07-16 16:17:31
问题 The two conditions that define a function as pure are as follows: No side effects (i.e. only changes to local scope are allowed) Always return the same output, given the same input If the first condition is always true, are there any times the second condition is not true? I.e. is it really only necessary with the first condition? 回答1: Here are a few counterexamples that do not change the outer scope but are still considered impure: function a() { return Date.now(); } function b() { return

Overlapping memory with sprintf(snprintf)

妖精的绣舞 提交于 2020-07-10 11:41:32
问题 Edit: What about if we had this char value_arr[8]; // value_arr is set to some value snprintf(value_arr, 8, "%d", *value_arr); is this behavior defined? Let's say for some ungainly reason I have char value_arr[8]; // value_arr is set to some value int* value_i = reinterpret_cast<int*>(value_arr); snprintf(value_arr, 8, "%d", *value_i); // the behaviour in question Is there a guarantee that, for example, if *value_i = 7, then value_arr will take on the value of "7". Is this behavior defined?