[cfe-dev] [RFC PATCH] C++0x trailing return type

Daniel Wallin daniel at boostpro.com
Tue Sep 28 02:42:09 PDT 2010


On Fri, Sep 24, 2010 at 4:31 PM, Douglas Gregor <dgregor at apple.com> wrote:
>
> On Sep 23, 2010, at 1:49 AM, Daniel Wallin wrote:
>> I'm attaching a patch that does that.
>
> This looks great! One comment and a request, then I'd like to see this go in:
>
[...]
> +    else if (FTI.TrailingReturnType) {
> +      Diag(D.getDeclSpec().getTypeSpecTypeLoc(),
> +           diag::err_trailing_return_without_auto)
> +        << FixItHint::CreateReplacement(D.getDeclSpec().getSourceRange(), "auto");
> +      D.setInvalidType(true);
> +    }
> +  }
>
> I like the use of the Fix-it hint, but I don't think that D.DeclSpec().getSourceRange() is always going to be the correct range. For example, I'd expect that we'd end up fixing
>
>        virtual int f(int) -> float;
>
> to
>
>        auto f(int) -> float;
>
>
> because the DeclSpec also contains function specifiers, storage specifiers, etc. It would be nice to have a test in test/FixIt that tests this kind of rewriting, to make sure we got it right.

Yes, I don't know why I thought it would be that simple. I think maybe
the replacement hint wasn't such a good idea in the first place. The
type name can span several files, function and storage specifiers can
occur inside the type source range, and it's just guesswork which of
the return types the user intended. It turned out very messy. I'm
attaching a patch with the __has_feature() support added, but with the
fixit-hint removed. Maybe if the feature really is desirable it can be
added later?

-- 
Daniel Wallin
BoostPro Computing
http://www.boostpro.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: trailing-return-3.patch
Type: application/octet-stream
Size: 16893 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20100928/c711ca7a/attachment.obj>


More information about the cfe-dev mailing list