language-lawyer

Is size_t large enough to represent size of any type? [duplicate]

邮差的信 提交于 2021-02-08 14:59:01
问题 This question already has answers here : C standard regarding sizeof overflowing size_t (1 answer) What is the maximum size of an array in C? (7 answers) Can calloc() allocate more than SIZE_MAX in total? (7 answers) Closed 1 year ago . Is size_t guaranteed to be large enough to represent size of any type? According to this reference: size_t can store the maximum size of a theoretically possible object of any type (including array). This is generally a reliable reference but I could not find

Compiler discrepencies in deduction of template parameter of nested alias template

寵の児 提交于 2021-02-08 14:47:29
问题 Consider the following code snippet where we we're trying to deduce the template parameter to the function foobar() : struct Bar { static constexpr auto size = 5; }; template <class T, class=std::make_index_sequence<T::size>> struct FooList; template <class T, std::size_t... Idxs> struct FooList<T, std::integer_sequence<std::size_t, Idxs...>> { }; struct Wrapper { template <class T> using list_type = FooList<T>; }; template <class T> void foobar(typename Wrapper::template list_type<T>) { }

braced-init-list and unsigned types

这一生的挚爱 提交于 2021-02-08 13:23:17
问题 gcc 8 and clang 7 do not accept the following code, which should default-construct a temporary of type unsigned int : unsigned int ui = unsigned int{}; clang 7 reports an error such as <source>:6:22: error: expected primary-expression before 'unsigned' Visual C++ 2015 and 2017 accept this. Obviously, this works with a type such as int , or any default-constructible class type. Is this correct C++14 code (and in that case a bug of clang and gcc)? If not, why not? Which types other than

braced-init-list and unsigned types

白昼怎懂夜的黑 提交于 2021-02-08 13:22:41
问题 gcc 8 and clang 7 do not accept the following code, which should default-construct a temporary of type unsigned int : unsigned int ui = unsigned int{}; clang 7 reports an error such as <source>:6:22: error: expected primary-expression before 'unsigned' Visual C++ 2015 and 2017 accept this. Obviously, this works with a type such as int , or any default-constructible class type. Is this correct C++14 code (and in that case a bug of clang and gcc)? If not, why not? Which types other than

Why is this a forward declaration in C++?

若如初见. 提交于 2021-02-08 12:16:40
问题 I will have the following code snippet in utilA.cpp: // utilB.h namespace xm { void zoo(struct tm timeval); //<-----line 0 } // utilA.cpp #include <utilB.h> //<----line 1 #include <time.h> //<----line 2 namespace xm { void foo() { struct tm time1 = {0}; //<----line 3 } } GCC complains when compiling utilA.cpp, error: variable 'xm::tm time1' has initializer but incomplete type It seems this is because the utilA.h is using struct tm in line 0, but without include the time.h , and the compiler

“Middle classes” in diamond inheritance graph using non-default virtual base constructor: why is it not a compile error?

偶尔善良 提交于 2021-02-08 09:58:08
问题 Consider a diamond inheritance graph (i.e., virtual base class). We know from previous questions that on construction the most derived class directly calls the default (0-arg) constructor of the (virtual) base. But we also know from answers to the previous question (e.g., here that if the "middle" classes in the diamond have constructors that are used by the most-derived class and those constructors "call" non-default constructors of their (virtual) base class (via the initialization list)

“Middle classes” in diamond inheritance graph using non-default virtual base constructor: why is it not a compile error?

南笙酒味 提交于 2021-02-08 09:56:53
问题 Consider a diamond inheritance graph (i.e., virtual base class). We know from previous questions that on construction the most derived class directly calls the default (0-arg) constructor of the (virtual) base. But we also know from answers to the previous question (e.g., here that if the "middle" classes in the diamond have constructors that are used by the most-derived class and those constructors "call" non-default constructors of their (virtual) base class (via the initialization list)

Why doesn't std::is_invocable work with templated operator() which return type is auto-deduced (eg. generic lambdas)

女生的网名这么多〃 提交于 2021-02-08 09:47:36
问题 c++17 introduces template <class Fn, class...ArgTypes> struct is_invocable: Determines whether Fn can be invoked with the arguments ArgTypes... . Formally, determines whether INVOKE(declval<Fn>(), declval<ArgTypes>()...) is well formed when treated as an unevaluated operand, where INVOKE is the operation defined in Callable . However, this template does not work with templated operator() which (direct or indirect) return type is auto-deduced: #include <type_traits> #include <iostream> struct

C99 floating point intermediate results

折月煮酒 提交于 2021-02-08 07:51:29
问题 As per the C99 standard: 6.3.1.8.2 : The values of floating operands and of the results of floating expressions may be represented in greater precision and range than that required by the type; the types are not changed thereby.52)> However, outside the scope of Annex F, we have: 5.2.4.2.2.7 : The values of operations with floating operands and values subject to the usual arithmetic conversions and of floating constants are evaluated to a format whose range and precision may be greater than

C99 floating point intermediate results

戏子无情 提交于 2021-02-08 07:51:10
问题 As per the C99 standard: 6.3.1.8.2 : The values of floating operands and of the results of floating expressions may be represented in greater precision and range than that required by the type; the types are not changed thereby.52)> However, outside the scope of Annex F, we have: 5.2.4.2.2.7 : The values of operations with floating operands and values subject to the usual arithmetic conversions and of floating constants are evaluated to a format whose range and precision may be greater than