patch: clarify missing template arguments when parsing base specifier
Nick Lewycky
nlewycky at google.com
Mon Aug 26 23:40:10 PDT 2013
On 26 August 2013 23:22, Chandler Carruth <chandlerc at google.com> wrote:
>
> On Mon, Aug 26, 2013 at 11:09 PM, Nick Lewycky <nlewycky at google.com>wrote:
>
>> On 26 August 2013 22:53, Chandler Carruth <chandlerc at google.com> wrote:
>>
>>> I think this case has more problems than just verbosity...
>>>
>>> On Mon, Aug 26, 2013 at 10:38 PM, Nick Lewycky <nlewycky at google.com>wrote:
>>>
>>>> a.cc:1:56: error: no template named 'Foox'; did you mean 'Foo'?
>>>> template <typename T> class Foo {}; class Bar : public Foox {};
>>>> [point at 'Foox' suggest 'Foo']
>>>>
>>>
>>> Why does it assume Foox is a template?
>>>
>>
>> It's already proven that it's not not-a-template.
>>
>> a.cc:1:29: note: 'Foo' declared here
>>>> template <typename T> class Foo {}; class Bar : public Foox {};
>>>> [point at 'Foo']
>>>> a.cc:1:56: error: expected template argument list after template-id
>>>> template <typename T> class Foo {}; class Bar : public Foox {};
>>>> [point at 'Foox']
>>>>
>>>
>>> And given that we then hit this error, why do we even consider the Foo
>>> typo correction? Do we prefer that over a "Fooxie" class due to shorter
>>> edit distance? That doesn't seem right. I would intuitively expect the lack
>>> of "<..." to be a stronger signal than any edit distance, and thus
>>> disqualify template-ids from the typo correction candidate set.
>>>
>>
>> No. We only go down this patch after we've done a lookup and typo
>> correction on non-templates, and found nothing.
>>
>
> I'm suggesting that a missing header or exceeding the maximum edit
> distance threshold seems just as plausible as using a template without
> template arguments. I'm not claiming that I have some strong reason to
> believe one interpretation or the other to be more likely, only that it
> doesn't seem clear-cut in either direction to me.
>
... if it can't find a template, then it doesn't mention templates:
$ echo 'class Bar : public Foo {};' | llvm/Debug+Asserts/bin/clang -x c++ -
<stdin>:1:20: error: expected class name
class Bar : public Foo {};
^
1 error generated.
$ echo 'template<typename T> class Fooa; class Foob {}; class Bar : public
Foo {};' | llvm/Debug+Asserts/bin/clang -x c++ -
<stdin>:1:68: error: unknown class name 'Foo'; did you mean 'Foob'?
template<typename T> class Fooa; class Foob {}; class Bar : public Foo {};
^~~
Foob
<stdin>:1:40: note: 'Foob' declared here
template<typename T> class Fooa; class Foob {}; class Bar : public Foo {};
^
1 error generated.
Today, clang emits the exact same diagnostic "expected class name" even
when you do have Foo declared as a template. That's the only thing I'm
trying to fix, but it has this weird side-effect in that even asking Sema
isTemplateName() causes does typo-correction, and when that typo-correction
succeeds it issues this "no template" diagnostic.
Nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130826/f650c6a7/attachment.html>
More information about the cfe-commits
mailing list