Variable iterating on itself – different behavior with different types

Please see edits below! For Each edits also added below under Edit2 More edits about ForEach and Collections at Edit3 One last edit about ForEach and Collections at Edit4 A final note about iteration behavior at Edit5 Part of the subtlety of this odd behavior in the semantics of variant evaluation when used as a … Read more

Local reference to std::cout captured by lambda without asking for it

There’s an open clang report that cover the case of implicit capture of references by lambda expressions, this is not limited to std::cout but to references variable that are found to refer to constant expressions. For more reference, the backing defect report on the CWG is CWG-1472 EDIT: Based on @Rakete1111 comment, I should have … Read more

C++11: Why is private member template accessible outside class?

This is definitely a compiler bug, and actually one that has been known for quite some time: GCC #47346 (first reported in Jan 2011) and Clang #15914 (first reported May 2013). Your __tklass is clearly private, and the template alias is not marked friend, so this should be a simple access error. The simplest reproduction … Read more

Why is std::unique_ptr::reset() always noexcept?

The requirements of the call to the function object Deleter are specific on this as listed in the requirements of the std::unique_ptr<T>::reset() member. From [unique.ptr.single.modifiers]/3, circa N4660 §23.11.1.2.5/3; unique_ptr modifiers void reset(pointer p = pointer()) noexcept; Requires: The expression get_deleter()(get()) shall be well formed, shall have well-defined behavior, and shall not throw exceptions. In general … Read more

Does the definition int a = 0, b = a++, c = a++; have defined behavior in C?

Does the definition int a = 0, b = a++, c = a++; have defined behavior in C? Yes, because C 2018 6.8 3 says these initializations (not all, see bottom) are evaluated in the order they appear: … The initializers of objects that have automatic storage duration, and the variable length array declarators of … Read more

Does the C++ standard guarantee that a failed insertion into an associative container will not modify the rvalue-reference argument?

Explicit and unequivocal NO. Standard doesn’t have this guarantee, and this is why try_emplace exists. See notes: Unlike insert or emplace, these functions do not move from rvalue arguments if the insertion does not happen, which makes it easy to manipulate maps whose values are move-only types, such as std::map<std::string, std::unique_ptr<foo>>. In addition, try_emplace treats … Read more

“is not required” == undefined behavior?

The wording has changed in various editions of the C++ standard, and in the recent draft cited in the question. (See my comments on the question for the gory details.) C++11 says: Other pointer comparisons are unspecified. C++17 says: Otherwise, neither pointer compares greater than the other. The latest draft, cited in the question, says: … Read more

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