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

Bug: legitimate code with variadic templates and variadic template aliases leads to an error.

Mikhail_K_3
Beginner
281 Views

Hi,

I've got an issue with the following code:

In test.cpp

    template <typename... Types>
    struct Variadic1 {};

    template <typename... Types>
    using MakeVariadic1 = Variadic1<Types...>;

    template <typename... Types>
    struct Variadic2 {};

    template <typename... Types>
    using MakeVariadic2 = Variadic2<MakeVariadic1<Types...>>;

    template <typename... Types>
    MakeVariadic2<Types...> test(Types...)
    {
        return MakeVariadic2<Types...>();
    }

    int main()
    {
        test(1);
    }

Command line and output:

 ~/tmp$ ~/soft/intel/system_studio_2015.2.050/bin/ia32/icpc -std=c++11 test.cpp -o test
test.cpp(21): error: template instantiation resulted in unexpected function type of "MakeVariadic2<int> (int)" (the meaning of a name may have changed since the template declaration -- the type of the template is "MakeVariadic2<Types...> (Types...)")
      test(1);
             ^
          detected during instantiation of "test" based on template argument <int> at line 21

compilation aborted for test.cpp (code 2)

~/tmp$ ~/soft/intel/system_studio_2015.2.050/bin/ia32/icpc --version
icpc (ICC) 15.0.0 20150121
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.

Note that Clang (3.4.1) and GCC (4.9.1) compile this code without errors.

Mikhail.

0 Kudos
2 Replies
Judith_W_Intel
Employee
281 Views

 

Yes this definitely looks like a bug and I can reproduce it with our latest development compiler. I have entered this in our internal bug tracking database as DPD200368349.

Thanks for reporting it and for the concise example!

Judy

0 Kudos
Judith_W_Intel
Employee
281 Views

 

We are still working on this one.

In the meantime the workaround is to not use the template alias in the return type for test(), i.e. change it the code inside #ifdef OK:

template <typename... Types>
#ifdef OK
Variadic2<Variadic1<Types...>>
#else
MakeVariadic2<Types...>
#endif
test(Types...)

instead of:

MakeVariadic2<Types...> test(Types...)

Judy

0 Kudos
Reply