[cfe-dev] Potential bug in class template argument deduction

Dimitry Andric via cfe-dev cfe-dev at lists.llvm.org
Tue Aug 15 03:40:41 PDT 2017


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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 223 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170815/8d5c61c1/attachment.sig>


More information about the cfe-dev mailing list