Parameter references in function types

David Vandevoorde daveed at edg.com
Thu May 6 19:48:22 UTC 2010


When mangling the signature of a template like:

	template<class T> auto f(T p)->decltype(*p);

we need a mechanism to describe the reference to "p".

Currently, the ABI says:

	"Function parameters referenced in a late-specified return type are handled similarly:
	
	
	  <function-param> ::= fp_	# first function parameter
			   ::= fp <parameter-2 non-negative number> _
	"

Unfortunately, this doesn't take into account that multiple levels of function declarators may be in flight.  E.g.:

	template<class T, class U> void f(T p, decltype(p)(*)(U p));          // (1)
and
	template<class T, class U> void f(T p, auto (*)(U p)->decltype(p));   // (2)

should produce different mangled names, but the "parameter number" is the same in both cases.


I'd therefore like to propose the following change.

Let L be the number of function prototype scopes from the innermost one (in which the parameter reference occurs) up to (and including) the one containing the declaration of the referenced parameter.  If the parameter declaration clause of the innermost function prototype scope has been completely seen, it is not counted (in that case -- which is perhaps the most common -- L can be zero).

If L is zero, keep the encoding above ("fp...").  If L is larger than zero, use the following production instead:

	  <function-param> ::= fL <L-1 non-negative number> p_	# first function parameter
			   ::= fL <L-1 non-negative number> p <parameter-2 non-negative number> _

Example (2) above would remain unchanged (parameter code "fp_"), but (1) would have L == 1 and the parameter code would therefore be "fL0p_".

Other examples:
	template<class T> void f(T p, decltype(p));                // L = 1
	template<class T> void g(T p, decltype(p) (*)());          // L = 1
	template<class T> void h(T p, auto (*)()->decltype(p));    // L = 1
	template<class T> void i(T p, auto (*)(T q)->decltype(q)); // L = 0
	template<class T> void j(T p, auto (*)(decltype(p))->T);   // L = 2
	template<class T> void k(T p, int (*(*)(T p))[sizeof(p)]); // L = 1


	Daveed





More information about the cxx-abi-dev mailing list