Generate fix-its for function parameters. Currently, the analyzer fixes one parameter at a time.
Fix-its for a function parameter includes:
- Fix the parameter declaration of the definition, result in a new overload of the function. We call the function with the original signature the old overload.
- For any other existing declaration of the old overload, mark it with the [[unsafe_buffer_usage]] attribute and generate a new overload declaration next to it.
- Creates a new definition for the old overload, which is simply defined by a call to the new overload.
Example,
void foo(int *p); void foo(int *p) { int x = p[5]; }
will be like the following after applying fix-its
[[unsafe_buffer_usage]] void foo(int * p); void foo(std::span<int> p); void foo(std::span<int> p) { ... } [[unsafe_buffer_usage]] void foo(int * p) { return foo(std::span<int>{p, <# size #>}); }
I suspect that it's always going to be "the whole TU", given that Sema is currently at the end of TU parsing (because that's where we put our analysis).
I recommend adding some tests with namespaces and other situations when functions are nested into something. Esp. when the out-of-line definition may be lexically available outside of the scope, eg.
where the compatibility overload has to go into the right namespace and the implementation of the compatibility overload has to be correctly prefixed with N::.