language-lawyer

What does “there is no smaller array object that satisfies these constraints” mean?

谁都会走 提交于 2020-06-10 08:43:42
问题 The draft n4659 for C++17 describes the general principes of the language in chapter 4. In chapter 4.5, The C++ object model [intro.object], I cannot understand the meaning of one sentence (emphasize mine) 3 If a complete object is created (8.3.4) in storage associated with another object e of type “array of N unsigned char” or of type “array of N std::byte” (21.2.1), that array provides storage for the created object if: (3.1) — the lifetime of e has begun and not ended, and (3.2) — the

Is reinterpret_cast type punning actually undefined behavior?

北城以北 提交于 2020-06-10 04:38:10
问题 It appears to be widely-held that type punning via reinterpret_cast is somehow prohibited (properly: "undefined behavior", that is, "behavior for which this International Standard imposes no requirements", with an explicit note that implementations may define behavior) in C++. Am I incorrect in using the following reasoning to disagree, and if so, why ? [expr.reinterpret.cast]/11 states: A glvalue expression of type T1 can be cast to the type “reference to T2 ” if an expression of type

What are 'constexpr' useful for?

﹥>﹥吖頭↗ 提交于 2020-06-09 16:53:29
问题 I really can't find any use of it. My first idea was that I could use it to implement 'Design by Contract' without using macros like this: struct S { S(constexpr int i) : S(i) { static_assert( i < 9, "i must be < 9" ); } S(int i); //external defintion char *pSomeMemory; }; But this wouldn't compile. I thought we could also use it to reference same-variable without the need of additional memory to be created when we want to avoid the get/setters in order to make instances to one member from

Does C++20 mandate source code being stored in files?

断了今生、忘了曾经 提交于 2020-06-09 08:09:27
问题 A slightly strange question, however, if I remember correctly, C++ source code doesn't require a file system to store its files. Having a compiler that scans handwritten papers via a camera would be a conforming implementation. Although practically not making that much sense. However C++20 now adds source location with file_name. Does this now imply that source code should always be stored in a file? 回答1: No, source code doesn't have to come from a file (nor go to a file). You can compile

Does C++20 mandate source code being stored in files?

扶醉桌前 提交于 2020-06-09 08:08:51
问题 A slightly strange question, however, if I remember correctly, C++ source code doesn't require a file system to store its files. Having a compiler that scans handwritten papers via a camera would be a conforming implementation. Although practically not making that much sense. However C++20 now adds source location with file_name. Does this now imply that source code should always be stored in a file? 回答1: No, source code doesn't have to come from a file (nor go to a file). You can compile

Does C++20 mandate source code being stored in files?

喜你入骨 提交于 2020-06-09 08:08:39
问题 A slightly strange question, however, if I remember correctly, C++ source code doesn't require a file system to store its files. Having a compiler that scans handwritten papers via a camera would be a conforming implementation. Although practically not making that much sense. However C++20 now adds source location with file_name. Does this now imply that source code should always be stored in a file? 回答1: No, source code doesn't have to come from a file (nor go to a file). You can compile

Why don't I need to specify “typename” before a dependent type in C++20?

人走茶凉 提交于 2020-06-09 07:52:31
问题 This bit of code compiled in C++20 (using gcc 10.1) without using the typename keyword before the dependent type std::vector<T>::iterator . Why does it compile? #include <vector> template<typename T> std::vector<T>::iterator // Why does this not require "typename" before it? f() { return {}; } int main() { auto fptr = &f<int>; } code playground 回答1: One of the new features in C++20 is Down with typename. In C++17, you had to provide the typename keyword in nearly all † dependent contexts to

Familiar template syntax for generic lambdas

生来就可爱ヽ(ⅴ<●) 提交于 2020-06-08 18:59:11
问题 For c++20 it is proposed to add the following syntax for generic lambdas p0428r2.pdf auto f = []<typename T>( T t ) {}; But the current implementation in gcc 8 did not accept the following instantiation: f<std::string>(""); Is that a implementation bug in gcc or a missing language feature? I know we talk about a proposal and not a approved specification. Complete example ( with comparison to template function syntax ): template <typename T> void n( T t ) { std::cout << t << std::endl; } auto

How to achieve a StoreLoad barrier in C++11?

谁说胖子不能爱 提交于 2020-06-08 04:52:27
问题 I want to write portable code (Intel, ARM, PowerPC...) which solves a variant of a classic problem: Initially: X=Y=0 Thread A: X=1 if(!Y){ do something } Thread B: Y=1 if(!X){ do something } in which the goal is to avoid a situation in which both threads are doing something . (It's fine if neither thing runs; this isn't a run-exactly-once mechanism.) Please correct me if you see some flaws in my reasoning below. I am aware, that I can achieve the goal with memory_order_seq_cst atomic store s

How to understand the sentence “full-expression must be a constant expression” which mentioned in the standard

大城市里の小女人 提交于 2020-05-30 08:27:07
问题 Ago, Some rules in the standard that say they are applied to expression , I was confused about whether these rules can also be applied to full-expression arbitrarily. I get an answers in that question. However, there are some rules like "the full-expression of the initialization shall be a constant expression. " in the standard. Such as: dcl.constexpr#9 basic.start.static#2 They all say that the full-expression must be a constant expression in these above links. The prior condition for a