Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mark as deprecated function parameters in C++14

Reading this blog post and its comments, I have noticed that it gives as an example the possibility of marking specific function parameters as deprecated, as in (exaple taken from the post):

// Deprecate a function parameter
int triple([[deprecated]] int x);

Now I was wondering, what is a good use case for such a feature? No one in the comments of that post or anywhere else I have searched seem to have a clue.

EDIT:

To see it in action, there is a compilable example on goldbolt

like image 686
bracco23 Avatar asked May 28 '19 10:05

bracco23


1 Answers

The rule is that the attribute is valid on, amongst other things, variable declarations (broadly). It's not specifically permitted for such declarations found in function arguments.

The original proposal, N3394, doesn't mention such a use case, either, and neither does the documentation for the original feature in GCC (which regardless accepts the equivalent usage) or in VS (I didn't check Clang).

As such, I think it's an "accident" that this is permitted, not something that anyone really had in mind as being useful.

Could it be useful to document deprecated defaulted arguments, as Artyer explores? Yes, potentially, and vaguely. But as Artyer also found, mainstream compilers don't actually react to this usage in a helpful manner.

So, at the present time, it's not useful, and the language feature wasn't particularly designed to be useful in this case.

like image 191
Lightness Races in Orbit Avatar answered Oct 12 '22 00:10

Lightness Races in Orbit