language-lawyer

Is taking the address of a member of an uninitialized object well defined?

南笙酒味 提交于 2019-12-19 08:13:04
问题 Consider the following example. When bar is constructed, it gives it's base type ( foo ) constructor the address of my_member.y where my_member is data member that hasn't been initialized yet. struct foo { foo(int * p_x) : x(p_x) {} int * x; }; struct member { member(int p_y) : y(p_y) {} int y; }; struct bar : foo { bar() : foo(&my_member.y), my_member(42) {} member my_member; }; #include <iostream> int main() { bar my_bar; std::cout << *my_bar.x; } Is this well defined? Is it legal to take

Differences of the interpretation of a non-dependent construct between definition context and point of instantiation in c++

跟風遠走 提交于 2019-12-19 07:39:37
问题 N4527 14.6 [temp.res]/p8 If a hypothetical instantiation of a template immediately following its definition would be ill-formed due to a construct that does not depend on a template parameter, the program is ill-formed; no diagnostic is required. If the interpretation of such a construct in the hypothetical instantiation is different from the interpretation of the corresponding construct in any actual instantiation of the template, the program is ill-formed; no diagnostic is required. [ Note:

Why do for(;;) loops behave like infinite loops?

冷暖自知 提交于 2019-12-19 07:18:08
问题 The answers to a recent question about for(;;){} loops (What does a for (;;) loop do) did not seem to answer something for me, so I thought that I would try to refine the question a bit. In particular, beyond knowing that for loops without conditionals are infinite loops, I would like to know why they are infinite loops. In the statement for (;_;){} , the _ is a conditional expression. My first guess would be that an empty expression might evaluate to 0 or NULL . But if you test: for (;;){}

Why can member variables not be used as defaults for parameters? [duplicate]

。_饼干妹妹 提交于 2019-12-19 07:09:14
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Nonstatic member as a default argument of a nonstatic member function Correct me if I am wrong, but the way I think default parameters work is this: When the compiler sees the function call, it starts pushing the parameters onto the stack. When it runs out of parameters, it will start pushing the defaults onto the stack until all required parameters are filled (I know this is a simplification, since parameters

Should flex item overflow the flex container instead of breaking lines?

人盡茶涼 提交于 2019-12-19 06:45:23
问题 I have this layout: A row flex container with a definite size, e.g. width: 175px A flex item With an indefinite flex-basis, e.g. flex-basis: content Which is inflexible, e.g. flex: none. Whose max-content size is larger than the available space Whose min-content size is smaller than the available space .flex-container { display: flex; width: 175px; border: 3px solid black; margin-bottom: 10px; } .flex-item { flex: none; border: 3px solid blue; margin: 3px; } .box { display: inline-block;

Why can't I decrement std::array::end()?

三世轮回 提交于 2019-12-19 05:57:57
问题 I'm creating a convenient display() function template for container types. The output for the last element is different from the rest, thus I check when myIterator != --cont.cend(); . This works for std::vector , but won't work for std::array . Why? Here's a MWE (not my actual code): std::vector<double> vec({1,2}); std::array<double, 2> arr({{1,2}}); auto vecIt = --vec.end(); // OK auto arrIt = --arr.end(); // error: lvalue required as decrement operand 回答1: It depends on how the iterator is

Why does reverse_iterator doubly define its nested types?

老子叫甜甜 提交于 2019-12-19 05:48:33
问题 It appears that the iterator adaptor reverse_iterator doubly defines most of its nested types. In particular, it inherits publicly from std::iterator which exposes iterator_category , value_type , difference_type , pointer and reference . Except for iterator_category and value_type , these are all explicitly typedef 'ed again in the class definition. 24.5.1.1 Class template reverse_iterator [reverse.iterator] namespace std { template <class Iterator> class reverse_iterator : public iterator

Is it illegal to use the h or hh length modifiers when the corresponding argument to printf was not a short / char?

依然范特西╮ 提交于 2019-12-19 05:47:06
问题 The printf family of functions provide a series of length modifiers, two of them being hh (denoting a signed char or unsigned char argument promoted to int ) and h (denoting a signed short or unsigned short argument promoted to int ). Historically, these length modifiers have only been introduced to create symmetry with the length modifiers of scanf and are rarely used for printf . Here is an excerpt of ISO 9899:2011 §7.21.6.1 “The fprintf function” ¶7: 7 The length modifiers and their

Correct behaviour of trivial statements involving expressions with volatile variables?

你说的曾经没有我的故事 提交于 2019-12-19 05:45:19
问题 Consider the following statements volatile int a = 7; a; // statement A volatile int* b = &a; *b; // statement B volatile int& c = a; c; // statement C Now, I've been trying to find a point in the standard that tells me how a compiler is to behave when coming across these statements. All I could find is that A (and possibly C) gives me an lvalue, and so does B: "§ 5.1.1.8 Primary expressions - General" says An identifier is an id-expression provided it has been suitably declared (Clause 7). [

Is the C++ Standard Library part of the C++ Language?

走远了吗. 提交于 2019-12-19 05:32:33
问题 Is the C++ Standard Library part of the C++ Language? ( note "language", not "standard"; both are, of course, part of the standard ). If so, why? If not, why not? The answer to this question may differ across C++98, C++03 and C++0x. It's not subjective because it can be inferred from wording/requirements in the relevant standards documents. 回答1: The very first words in all of the versions of the standard I've seen are "This International Standard specifies requirements for implementations of