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

Douglas Gregor dgregor at apple.com
Fri Oct 1 12:46:11 PDT 2010


On Sep 28, 2010, at 2:42 AM, Daniel Wallin wrote:

> 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?

Sure. I've committed your patch, with a few tweaks, in Clang r115322. Thanks!

	- Doug



More information about the cfe-dev mailing list