[PATCH] D61458: [hip] Relax CUDA call restriction within `decltype` context.
John McCall via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu May 2 19:55:01 PDT 2019
rjmccall added a comment.
In D61458#1488972 <https://reviews.llvm.org/D61458#1488972>, @hfinkel wrote:
> In D61458#1488970 <https://reviews.llvm.org/D61458#1488970>, @jlebar wrote:
>
> > Here's one for you:
> >
> > __host__ float bar();
> > __device__ int bar();
> > __host__ __device__ auto foo() -> decltype(bar()) {}
> >
> >
> > What is the return type of `foo`? :)
> >
> > I don't believe the right answer is, "float when compiling for host, int when compiling for device."
>
>
> So, actually, I wonder if that's not the right answer. We generally allow different overloads to have different return types.
Only if they also differ in some other way. C++ does not (generally) have return-type-based overloading. The two functions described would even mangle the same way if CUDA didn't include host/device in the mangling.
(Function templates can differ only by return type, but if both return types successfully instantiate for a given set of (possibly inferred) template arguments then the templates can only be distinguished when taking their address, not when calling.)
I think I've said before that adding this kind of overloading is not a good idea, but since it's apparently already there, you should consult the specification (or at least existing practice) to figure out what you're supposed to do.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61458/new/
https://reviews.llvm.org/D61458
More information about the cfe-commits
mailing list