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



_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to