Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
165 Views

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

Jump to solution

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

Accepted Solutions
Highlighted
Moderator
165 Views

This will be fixed in the upcoming release.

View solution in original post

0 Kudos
3 Replies
Highlighted
Moderator
165 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
Highlighted
Moderator
166 Views

This will be fixed in the upcoming release.

View solution in original post

0 Kudos
Highlighted
Moderator
53 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