Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Mikhail_K_3
Beginner
40 Views

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

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
40 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

Judith_W_Intel
Employee
40 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