language-lawyer

Incomplete types in member function definitions

允我心安 提交于 2020-08-03 17:34:36
问题 [dcl.fct.def] p2 states: The type of a parameter or the return type for a function definition shall not be an incomplete or abstract (possibly cv-qualified) class type in the context of the function definition unless the function is deleted. And [class.mem] p7 states: A class is considered a completely-defined object type (or complete type) at the closing } of the class-specifier . The class is regarded as complete within its complete-class contexts; otherwise it is regarded as incomplete

When is there an UB because the best overload match was not found by ADL at the point of instantiation?

℡╲_俬逩灬. 提交于 2020-08-02 07:47:32
问题 When a function body is instantiated, dependent function call overload resolution should find the best match in associated namespace through ADL, otherwise the behavior is undefined, [temp.dep.candidate]§1 If the call would be ill-formed or would find a better match had the lookup within the associated namespaces considered all the function declarations with external linkage introduced in those namespaces in all translation units, not just considering those declarations found in the template

Partial specialization of single type template parameter class template using non-type template parameter through a dependent type

拟墨画扇 提交于 2020-07-31 07:19:10
问题 All standard references below refers to N4659: March 2017 post-Kona working draft/C++17 DIS. Consider the following snippet: #include <type_traits> template <int N> struct num {}; template <typename> struct A; // (1) template <int N> struct A<num<N>> { using type = bool; }; // (2) template <long N> struct A<num<N>> { using type = char; }; static_assert(!std::is_same_v<long, int>, ""); // (A) static_assert(std::is_same_v<A<num<1>>::type, bool>, ""); int main() {} The static_assert at (A) is

Partial specialization of single type template parameter class template using non-type template parameter through a dependent type

吃可爱长大的小学妹 提交于 2020-07-31 07:19:09
问题 All standard references below refers to N4659: March 2017 post-Kona working draft/C++17 DIS. Consider the following snippet: #include <type_traits> template <int N> struct num {}; template <typename> struct A; // (1) template <int N> struct A<num<N>> { using type = bool; }; // (2) template <long N> struct A<num<N>> { using type = char; }; static_assert(!std::is_same_v<long, int>, ""); // (A) static_assert(std::is_same_v<A<num<1>>::type, bool>, ""); int main() {} The static_assert at (A) is

Ternary operator implicit cast to base class

霸气de小男生 提交于 2020-07-28 06:33:06
问题 Consider this piece of code: struct Base { int x; }; struct Bar : Base { int y; }; struct Foo : Base { int z; }; Bar* bar = new Bar; Foo* foo = new Foo; Base* returnBase() { Base* obj = !bar ? foo : bar; return obj; } int main() { returnBase(); return 0; } This doesn't work under Clang or GCC, giving me : error: conditional expression between distinct pointer types ‘Foo*’ and ‘Bar*’ lacks a cast Base* obj = !bar ? foo : bar; Which means for it to compile I have to change the code to : Base*

Is the size of an object equivalent to the size of another based upon the same alignment and/or representation?

萝らか妹 提交于 2020-07-23 06:45:32
问题 The C standard states (emphasize mine): 28 A pointer to void shall have the same representation and alignment requirements as a pointer to a character type. 48) Similarly, pointers to qualified or unqualified versions of compatible types shall have the same representation and alignment requirements. All pointers to structure types shall have the same representation and alignment requirements as each other. All pointers to union types shall have the same representation and alignment

Name lookup for members of the current instantiation and members of unknown specializations

二次信任 提交于 2020-07-22 18:35:27
问题 Does any wording specify how the names of members of unknown specializations and of the current instantiation are looked up? [temp.res] p10 has a very informal definition: When looking for the declaration of a name used in a template definition, the usual lookup rules are used for non-dependent names. The lookup of names dependent on the template parameters is postponed until the actual template argument is known. [temp.dep] p2 specifies that dependent names only apply to unqualified-id's in

Name lookup for members of the current instantiation and members of unknown specializations

牧云@^-^@ 提交于 2020-07-22 18:35:25
问题 Does any wording specify how the names of members of unknown specializations and of the current instantiation are looked up? [temp.res] p10 has a very informal definition: When looking for the declaration of a name used in a template definition, the usual lookup rules are used for non-dependent names. The lookup of names dependent on the template parameters is postponed until the actual template argument is known. [temp.dep] p2 specifies that dependent names only apply to unqualified-id's in

How to model a covariant association-class in UML?

╄→гoц情女王★ 提交于 2020-07-22 10:59:20
问题 In short I would like to model a covariant association between two classes, that can each be specialized. I need to show the specialization of the related association-classes. But I want to avoid that my model could mean that there are redundant associations (i.e. one between the generalizations and one between the specializations. Step by step explanation of the problem I have in an UML class diagram a many-many association between a Person and a Contract . A person can be involved in

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

荒凉一梦 提交于 2020-07-20 23:43:15
问题 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