====== 2016-05-18 - C++ and function signatures ====== [[wp>C++]] is complex. i constantly get surprised by corner cases. few days back [[wp>http://szborows.blogspot.cz|SÅ‚awek]] asked me if i know, if return type of a function is a part of a function's signature. i said "no" and he replied "well -- i though so too". it runs out that the correct answer is... "it depends". let's have a look at some examples: int f1(int); template int f2(int); template struct A { template int f3(int); }; template struct B { int f4(int); }; void foo() { f1(1); f2(2); A a; a.f3(3); B b; b.f4(4); } now let's see what's the compiler's output: clang++ -Wall -std=c++14 syms.cpp -c nm syms.o | c++filt | grep U and we get: U f1(int) U int f2(int) U int A::f3(int) U B::f4(int) note that //f2// and //f3// do have return types in their signatures, while //f1// and //f4// don't! as usually -- that's the corner case in the C++ spec. looking at [[wp>C++14]] spec 1.3.17 through 1.3.22, explains the secret: * 1.3.17 -- //function//: name, parameter type list (8.3.5), and enclosing namespace (if any). * 1.3.18 -- //function template//: name, parameter type list (8.3.5), enclosing namespace (if any), **return type**, and template parameter list. * 1.3.19 -- //function template specialization//: signature of the **template of which it is a specialization** and its template arguments (whether explicitly specified or deduced). * 1.3.20 -- //class member function//: name, parameter type list (8.3.5), class of which the function is a member, cv-qualifiers (if any), and ref-qualifier (if any) * 1.3.21 -- //class member function template//: name, parameter type list (8.3.5), class of which the function is a member, cv-qualifiers (if any), ref-qualifier (if any), **return type**, and template parameter list * 1.3.22 -- //class member function template specialization//: signature of the member function **template of which it is a specialization** and its template arguments (whether explicitly specified or deduced). long story short -- if you have a template (member) function (partial) (specialization), return type __is__ a part of the signature. otherwise __its not__.