[cfe-dev] Potential bug in class template argument deduction
Hamza Sood via cfe-dev
cfe-dev at lists.llvm.org
Tue Aug 15 08:09:53 PDT 2017
Hi John,
I’ve filed a bug here: https://bugs.llvm.org/show_bug.cgi?id=34195
> On 15 Aug 2017, at 15:50, John McCall <rjmccall at apple.com> wrote:
>
>> On Aug 15, 2017, at 7:00 AM, Hamza Sood via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>> The GCC C++ status page (https://gcc.gnu.org/projects/cxx-status.html) shows that class template argument deduction wasn’t implemented until GCC-7.
>>
>> However Clang’s status page also reports it as implemented (in SVN builds), but Clang built from SVN trunk rejects that code.
>
> The template-argument inference logic in the proposed standard has undergone repeated late revisions; I expect that both GCC and Clang implement some intermediate version that isn't quite fully what's specified in the current draft. Of course that's something we should fix. Please file a bug on bugs.llvm.org and we'll take a look.
>
> John.
>
>>
>>> On 15 Aug 2017, at 11:53, Dimitry Andric wrote:
>>>
>>> Hm, it appears to depend on the gcc version:
>>>
>>> $ g++6 -std=c++17 test.cpp
>>> test.cpp: In function 'int main()':
>>> test.cpp:8:9: error: missing template arguments before 'b'
>>> Base b(d);
>>> ^
>>>
>>> However, gcc 7.1.1 does accept it. So maybe this is something very new?
>>>
>>> -Dimitry
>>>
>>>> On 15 Aug 2017, at 12:46, Hamza Sood <hamza_sood at me.com> wrote:
>>>>
>>>> Sorry, I should’ve been more clear. I’m talking about C++17 class template argument deduction.
>>>>
>>>> If you pass “-std=c++17” to GCC, then it compiles the code fine. However Clang still rejects it.
>>>>
>>>> (Sending again because I forgot to reply all)
>>>>
>>>>>> On 15 Aug 2017, at 11:40, Dimitry Andric wrote:
>>>>>>
>>>>>> On 15 Aug 2017, at 12:04, Hamza Sood via cfe-dev <cfe-dev at lists.llvm.org> wrote:
>>>>>>
>>>>>> template<typename T>
>>>>>> class Base { };
>>>>>>
>>>>>> class Derived: public Base<int> { };
>>>>>>
>>>>>> int main() {
>>>>>> Derived d;
>>>>>> Base b(d);
>>>>>> return 0;
>>>>>> }
>>>>>>
>>>>>>
>>>>>> Clang rejects that code, saying it can’t deduce the template parameters for Base.
>>>>>> However I think that code is valid; it’s accepted by GCC.
>>>>>
>>>>> Not here, with gcc 6.4.0:
>>>>>
>>>>> $ g++ -c test.cpp
>>>>> test.cpp: In function 'int main()':
>>>>> test.cpp:8:9: error: missing template arguments before 'b'
>>>>> Base b(d);
>>>>> ^
>>>>>
>>>>> The declaration should use Base<int> instead.
>>>>>
>>>>>
>>>>>> Is this a Clang bug?
>>>>>
>>>>> No, though clang's error message is substantially more confusing, in my opinion:
>>>>>
>>>>> $ clang++ -c test.cpp
>>>>> test.cpp:8:4: error: unknown type name 'Base'; did you mean 'Derived::Base'?
>>>>> Base b(d);
>>>>> ^~~~
>>>>> Derived::Base
>>>>> test.cpp:2:7: note: 'Derived::Base' declared here
>>>>> class Base { };
>>>>> ^
>>>>>
>>>>> It should give a similar suggestion as gcc does.
>>>>>
>>>>> -Dimitry
>>>>>
>>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170815/49664060/attachment.html>
More information about the cfe-dev
mailing list