void foo() @safe
{
}
void foo() nothrow
{
}
void bar() @safe
{
foo();
}
void bar() nothrow
{
foo();
}
----
This currently fails, because foo() is said to match both functions,
but at the same time it is not an error to declare the overloads.
The enhancement is to use attribute sets to resolve overloads.
- The attribute set of the caller must be a subset of the callee.
- The attribute sets of overloads must be disjoint if they have the
same signature otherwise.
----
Some C++ AMP work has been done on this topic for restrict overloading.
http://blogs.msdn.com/b/nativeconcurrency/archive/2012/03/29/function-overloading-with-restrict-in-c-amp.aspx
Comment #1 by issues.dlang — 2013-02-14T10:21:30Z
I don't think that it's going to work to overload on any of these attributes. They're inferred for templated functions, which means that the functions being used within a function must have their @safety, purety, and nothrow-ity determined before they're determined for the function itself. So, you can't reasonably determine an overload of nothrow, @safe, or pure based on the caller. It has to be based on the arguments (which is _always_ how function overloading is determined).
Rather, it would be better to make it so that overloads with the same parameters are illegal.
Comment #2 by code — 2013-02-14T13:37:05Z
> They're inferred for templated functions
Right, I didn't thought of inference.
But couldn't it still work with the non-inferred original type.
Comment #3 by code — 2013-02-14T13:40:26Z
> Rather, it would be better to make it so that overloads with the same
parameters are illegal.
Yes, that would be one solution, but I do think this could come in handy with UDA.
Comment #6 by razvan.nitu1305 — 2022-09-08T14:10:27Z
I think we can safely close this as WONTFIX. Having a distinction between functions that have their attributes inferred and functions that don't complicates the language for a minor benefit.