Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7957 Discussions

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

Vaverka__Filip
Beginner
1,240 Views

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>();
...

 

0 Kudos
1 Solution
Viet_H_Intel
Moderator
1,240 Views

This will be fixed in the upcoming release.

View solution in original post

0 Kudos
3 Replies
RahulV_intel
Moderator
1,240 Views

Hi Filip,

Thanks for reporting this bug. It is reproducible at my end. I will escalate this issue to the concerned team,

 

--Rahul

0 Kudos
Viet_H_Intel
Moderator
1,241 Views

This will be fixed in the upcoming release.

0 Kudos
Viet_H_Intel
Moderator
1,128 Views

This has been fixed in OneAPI tool kit. We will no longer respond to this thread.  

If you require additional assistance from Intel, please start a new thread. Any further interaction in this thread will be considered community only.


Thanks,


0 Kudos
Reply