Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
Announcements
Intel Customer Support will be observing the Martin Luther King holiday on Monday, Jan. 17, and will return on Tues. Jan. 18.
For the latest information on Intel’s response to the Log4j/Log4Shell vulnerability, please see Intel-SA-00646
7590 Discussions

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

Vaverka__Filip
Beginner
554 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
554 Views

This will be fixed in the upcoming release.

View solution in original post

3 Replies
RahulV_intel
Moderator
554 Views

Hi Filip,

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

 

--Rahul

Viet_H_Intel
Moderator
555 Views

This will be fixed in the upcoming release.

View solution in original post

Viet_H_Intel
Moderator
442 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,


Reply