Why can C++ deduce template arguments on the right side of an assignment operator from the left side?

Is this standard behavior? Yes it is. Template argument deduction also happens when you take the address of a function template (such as you do when assigning to or initializing a function pointer). It’s explicitly allowed in [temp.deduct.funcaddr]/1: Template arguments can be deduced from the type specified when taking the address of an overloaded function. … Read more

g++ and clang++ different behaviour with recursive initialization of a static member

It is unspecified. Both compilers are right. Here are the relevant pieces from cppreference “initialization”. Static initialization For all other non-local static and thread-local variables, Zero initialization takes place So for all these variables, they are zero when the program loads. Then: Dynamic initialization After all static initialization is completed, dynamic initialization of non-local variables … Read more

Is a class with deleted copy-constructor trivially copyable?

Update: The proposed resolution of CWG 1734, currently in “ready” status, would modify [class]/p6 to read: A trivially copyable class is a class: where each copy constructor, move constructor, copy assignment operator, and move assignment operator (12.8 [class.copy], 13.5.3 [over.ass]) is either deleted or trivial, that has at least one non-deleted copy constructor, move constructor, … Read more

The validity of lambda expression with omitted parameter list in C++23

Thanks for reminding me of how pointless this feature is. The correct answer is: no, that’s not a well-formed lambda. The grammar is defined in [expr.prim.lambda.general]: In our case, to start with we have: []<auto> noexcept requires true {}; [] is the lambda-introducer <auto> matches <template-parameter-list> and now we know we’re the 2nd kind lambda-expression. … Read more

Does struct with reference member have unique object representation?

Firstly, references are not objects. Objects are specified in [intro.object] and references in [dcl.ref]. Subobjects are objects ([intro.object]). Therefore reference members are not subobjects and therefore a class containing only reference members (and no bases) has no subobjects (even though it has data members). [meta.unary.prop] The predicate condition for a template specialization has_­unique_­object_­representations shall be … Read more

Why doesn’t the standard consider a template constructor as a copy constructor?

Let’s put templates aside for a second. If a class doesn’t declare a copy constructor, an implicitly defaulted one is generated. It may be defined as deleted, but it’s defaulted nonetheless. A member template is not a member function. Members are instantiated from it only when needed. So how can a compiler know from the … Read more

Why do proc-macros have to be defined in proc-macro crate?

Procedural macros are fundamentally different from normal dependencies in your code. A normal library is just linked into your code, but a procedural macro is actually a compiler plugin. Consider the case of cross-compiling: you are working on a Linux machine, but building a WASM project. A normal crate will be cross-compiled, generate WASM code … Read more

Can constexpr be combined with volatile?

Yes, this is valid, there was defect report 1688: Volatile constexpr variables that was filed for this, saying: There does not appear to be language in the current wording stating that constexpr cannot be applied to a variable of volatile-qualified type. Also, the wording in 5.19 [expr.const] paragraph 2 referring to “a non-volatile object defined … Read more

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