std::is_constructible on incomplete types

The behavior is undefined. [meta.unary.prop] template <class T, class… Args> struct is_constructible; T and all types in the parameter pack Args shall be complete types, (possibly cv-qualified) void, or arrays of unknown bound. That’s a precondition of the meta-function. A contract that your code violates. libc++ is being generous by notifying you. Mind you, that … Read more

Difference of type between “fun” and “&fun”?

Both assertions succeed because they are applied to the type T deduced from function argument. In both cases it will be deduced as a pointer to function because functions decay to a pointer to function. However if you rewrite assertions to accept types directly then first one will fail: static_assert(is_same<void(*)(), decltype(fun)>::value); static_assert(is_same<void(*)(), decltype(&fun)>::value); online compiler

Is the compiler allowed to optimise out private data members?

Possible in theory (along with unused public members), but not with the kind of compiler ecosystem we’re used to (targeting a fixed ABI that can link separately-compiled code). Removing unused members could only be done with whole-program optimization that forbids separate libraries1. Other compilation units might need to agree on sizeof(foo), but that wouldn’t be … Read more

In which versions of the C++ standard does “(i+=10)+=10” have undefined behaviour?

tl;dr: The sequence of the modifications and reads performed in (i+=10)+=10 is well defined in both C++98 and C++11, however in C++98 this is not sufficient to make the behavior defined. In C++98 multiple modifications to the same object without an intervening sequence-point results in undefined behavior, even when the order of those modifications is … Read more

Can ptrdiff_t represent all subtractions of pointers to elements of the same array object?

Is it even possible for the result of i-j not to be in the range of representable values of ptrdiff_t? Yes, but it’s unlikely. In fact, [support.types.layout]/2 does not say much except the proper rules about pointers subtraction and ptrdiff_t are defined in [expr.add]. So let us see this section. [expr.add]/5 When two pointers to … Read more

Return value of placement new

I’m surprised no one has mentioned this cheap counterexample yet: struct foo { static foo f; // might seem dubious but doesn’t violate anything void* operator new(size_t, void* p) {return &f;} }; Demo on Coliru. Unless a class-specific placement version is called, however, your assertion should hold. Both expressions have to represent the same address … Read more

Why is this pointer null

The size limit of an object is implementation defined, per Annex B of the standard [1]. Your struct is of an absurd size. If the struct is: struct Foo { char arr1[INT_MAX]; //char arr2[INT_MAX]; char ch1; char ch2; }; … the size of your struct in a relatively recent version of 64-bit MSVC appears to … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)