Quantcast
Channel: Intel® Software - Intel® C++ Compiler
Viewing all articles
Browse latest Browse all 1175

C++ injected-class-name mishandled in templated class

$
0
0

Intel C++ Compiler (icpc (ICC) 19.1.0.166 20191121) seems to mishandle “injected-class-name” as described in (C++ 2014 Standard draft: 14.6.1). The compiler seems to pass type-name instead of template-name as a template template argument when instantiating method/function template from within template class itself (see code below). This seems to violate second bullet-point (see https://en.cppreference.com/w/cpp/language/injected-class-name#In_class_template), which states that the injected-class-name is treated as a template-name of the class template itself when: "it is used as a template argument that corresponds to a template template parameter".

Therefore following code fails to compile ("Foo" in "Bar<Foo>()" call seems to be handled as "Bar<Foo<int> >()" instead as template-name itself):

template<typename T>
class Foo {
public:
    template<template<typename> class VT>
    void Bar() {}

    void Bar2() {
        Bar<Foo>();
    }
};

int main(int argc, char *argv[])
{
    Foo<int> foo;
    foo.Bar2();
    return 0;
}

This can be fixed as

template<typename T>
class Foo {
public:
    template<template<typename> class VT>
    void Bar() {}

    void Bar2() {
        Bar<::Foo>();
    }
};

int main(int argc, char *argv[])
{
    Foo<int> foo;
    foo.Bar2();
    return 0;
}

or by aliasing "Foo" template as in

template<typename TA>
using FooAlias = Foo<TA>;
...
Bar<FooAlias>();
...

 


Viewing all articles
Browse latest Browse all 1175

Trending Articles