How does the linker handle identical template instantiations across translation units?

C++ requires that an inline function definition be present in a translation unit that references the function. Template member functions are implicitly inline, but also by default are instantiated with external linkage. Hence the duplication of definitions that will be visible to the linker when the same template is instantiated with the same template arguments … Read more

Dependent type or argument in decltype in function definition fails to compile when declared without decltype

Because when there is a template parameter involved, decltype returns an unqiue dependent type according to the standard, see below. If there is no template parameter then it resolves to an obvious size_t. So in this case you have to choose either both declaration and definition have an independent expression (e.g. size_t/decltype(sizeof(int))), as a return … Read more

Does extern template prevent inlining of functions?

The idea behind extern templates is to make explicit template instantiations more useful. As you know, in C++03, you can explicitly instantiate a template using this syntax: template class SomeTemplateClass<int>; template void foo<bool>(); This tells the compiler to instantiate the template in the current translation unit. However, this doesn’t stop implicit instantiations from happening: the … Read more

gcc and clang implicitly instantiate template arguments during operator overload resolution

The entire point of the matter is ADL kicking in: N3797 – [basic.lookup.argdep] When the postfix-expression in a function call (5.2.2) is an unqualified-id, other namespaces not considered during the usual unqualified lookup (3.4.1) may be searched, and in those namespaces, namespace-scope friend function or function template declarations (11.3) not otherwise visible may be found. … Read more

Issue with visual studio template & directory creation

To create solution at root level (not nest them in subfolder) you must create two templates: 1) ProjectGroup stub template with your wizard inside that will create new project at the end from your 2) Project template use the following approach for that 1. Add template something like this <VSTemplate Version=”2.0.0″ xmlns=”http://schemas.microsoft.com/developer/vstemplate/2005″ Type=”ProjectGroup”> <TemplateData> <Name>X … Read more

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

Constexpr is not allowed in declaration of friend template specialization?

GCC is wrong here. All references are to N4431, the latest C++ WD. [tl;dr: There’s a difference between a function being inline (or more precisely, being an inline function, as defined in 7.1.2/2) and being declared with the inline specifier. The constexpr specifier makes a function inline, but isn’t an inline specifier.] Specifiers are described … Read more

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