language-lawyer

How does the number of braces affect uniform initialization?

不打扰是莪最后的温柔 提交于 2019-12-20 08:40:59
问题 Consider the following code snippet: #include <iostream> struct A { A() {} A(const A&) {} }; struct B { B(const A&) {} }; void f(const A&) { std::cout << "A" << std::endl; } void f(const B&) { std::cout << "B" << std::endl; } int main() { A a; f( {a} ); // A f( {{a}} ); // ambiguous f( {{{a}}} ); // B f({{{{a}}}}); // no matching function } Why does each call fabricate the corresponding output? How does the number of braces affect uniform initialization? And how does brace elision affect all

Addition assignment += behavior in expression

廉价感情. 提交于 2019-12-20 08:33:36
问题 Recently I came across this question: Assignment operator chain understanding. While answering this question I started doubting my own understanding of the behavior of the addition assignment operator += or any other operator= ( &= , *= , /= , etc.). My question is, when is the variable a in the expressions below updated in place, so that its changed value is reflected in other places in the expression during evaluation, and what is the logic behind it? Please take a look at following two

Addition assignment += behavior in expression

ε祈祈猫儿з 提交于 2019-12-20 08:32:24
问题 Recently I came across this question: Assignment operator chain understanding. While answering this question I started doubting my own understanding of the behavior of the addition assignment operator += or any other operator= ( &= , *= , /= , etc.). My question is, when is the variable a in the expressions below updated in place, so that its changed value is reflected in other places in the expression during evaluation, and what is the logic behind it? Please take a look at following two

Can an implementation consider hints as actual statements?

最后都变了- 提交于 2019-12-20 05:12:59
问题 In C, the register storage qualifier is an hint to the implementation that such identifier should be accessed as fast as possible (e.g. stored in a CPU register). §6.7.1 A declaration of an identifier for an object with storage-class specifier register suggests that access to the object be as fast as possible. The extent to which such suggestions are effective is implementation-defined. and §6.7.3 The intended use of the restrict qualifier (like the register storage class) is to promote

Can I expand a parameters pack and define an arguments list with it?

陌路散爱 提交于 2019-12-20 05:02:41
问题 From [temp.variadic] (working draft) it seemed to me that a parameters pack can be expanded while defining an arguments list of another template class or function. Consider the following class: template<typename... T> struct S { template<T... I> void m() {} }; int main() { S<int, char> s; // ... } The intent is to capture the types used to specialize the template class S and use them to define an arguments list of non-type parameters for the member method m ( T is limited to a few types, of

How does placement new know which layout to create?

时光总嘲笑我的痴心妄想 提交于 2019-12-20 04:07:11
问题 #include <iostream> #include <typeinfo> struct A { int a; }; struct B : virtual A { int b; }; struct C : virtual A { int c; }; struct D : B,C { int d; }; int main() { D complete; B contiguous; B & separate = complete; B * p[2] = {&separate, &contiguous}; // two possible layouts for B: std::cout<< (int)((char*)(void*) &p[0]->a -(char*)(void*)&p[0]->b)<<" "<< sizeof(*p[0])<< "\n"; std::cout<< (int)((char*)(void*) &p[1]->a -(char*)(void*)&p[1]->b)<<" "<< sizeof(*p[1])<< "\n"; alignas(B) char

What formatting context applies to elements that don't create their own?

大憨熊 提交于 2019-12-20 03:52:50
问题 When I read the CSS Visual formatting specification, I see that Boxes in the normal flow belong to a formatting context, which in CSS 2.2 may be table, block or inline. Block-level boxes participate in a block formatting context. Inline-level boxes participate in an inline formatting context. But not all boxes create a Block Formatting Context. Where in the docs does it describe the normal flow for boxes that don't create a BFC, and if they don't create one, what formatting context applies?

What does “The template arguments of a specialization are deduced from the arguments of the primary template” mean?

隐身守侯 提交于 2019-12-20 03:19:56
问题 N4567 14.5.5.1 [temp.class.spec.match]p4 In a type name that refers to a class template specialization, (e.g., A) the argument list shall match the template parameter list of the primary template. The template arguments of a specialization are deduced from the arguments of the primary template. template<class T1, class T2, int I> class A { }; // #1 template<class T, int I> class A<T, T*, I> { }; // #2 A<int, int, 1> a1; // uses #1 Does this "deduced" mean 14.8.2.5 [temp.deduct.type]? Template

Declaration vs definition in C

╄→尐↘猪︶ㄣ 提交于 2019-12-20 03:13:34
问题 Consider the code: int main(void) { int a; } As far as I know, int a; is a definition, as it causes storage to be reserved. Citing the C standard (N1570 Committee Draft — April 12, 2011): 6.7/5 Semantics A declaration specifies the interpretation and attributes of a set of identifiers. A definition of an identifier is a declaration for that identifier that: — for an object, causes storage to be reserved for that object; ... Here comes the question: the compiler may optimize away the storage,

Is a glvalue integral constant expression a constant expression?

我怕爱的太早我们不能终老 提交于 2019-12-20 02:38:29
问题 N4527 5.20 [expr.const]p3 An integral constant expression is an expression of integral or unscoped enumeration type, implicitly converted to a prvalue, where the converted expression is a core constant expression. 5.20 [expr.const]p5 A constant expression is either a glvalue core constant expression whose value refers to an entity that is a permitted result of a constant expression (as defined below), or a prvalue core constant expression whose value is an object where, for that object and