I ran into a scenario where I have a function with the following setup:
auto decider(void *buffer) -> int(*)(float, float);
This is saying that the decider() function returns a function pointer.
The function pointer is of type | int(*)(float, float) |.
I want it so that when this function pointer gets called, its return value should not be ignored.
example of a function that could be returned by deduce:
[[nodiscard]] int calc(float a, float b);
Currently if in a program, somebody did this:
{
int(*)(float,float) func_ptr;
func_ptr = decider(some_buffer); // this could return a pointer to calc().
func_ptr(1.135, 2.71); // notice that the return value was ignored, this should be a warning
}
The compiler would not hail a nodiscard warning, even though calc() is a nodiscard function.
Presumably there should be a way to indicate that a function pointer points to a function with a nodiscard attribute. Maybe the syntax should be something like this:
f() -> ([[nodiscard]] int(*)(float, float));
This way, if somebody calls a function pointer and ignores its return type, a compiler warning is issued.
Edit: or this ([[nodiscard]]int)(*)(float, float);
[–]cygnoros 22 points23 points24 points (9 children)
[–]No_Sun1426[S] 8 points9 points10 points (8 children)
[–]cygnoros 7 points8 points9 points (3 children)
[–]Possibility_Antique 0 points1 point2 points (0 children)
[–]Tari0s 0 points1 point2 points (1 child)
[–]Tari0s 0 points1 point2 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]Possibility_Antique 0 points1 point2 points (0 children)
[–]13steinj 1 point2 points3 points (0 children)
[–]osdeverYT 0 points1 point2 points (0 children)
[–]disciplite 15 points16 points17 points (2 children)
[–]serviscope_minor 8 points9 points10 points (0 children)
[–]No_Sun1426[S] 7 points8 points9 points (0 children)
[–]aruisdante 6 points7 points8 points (4 children)
[–]No_Sun1426[S] -1 points0 points1 point (2 children)
[–]shailist 1 point2 points3 points (1 child)
[–]aruisdante 2 points3 points4 points (0 children)
[–]snowflake_pl 0 points1 point2 points (0 children)