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

Problem with initializer list

Joaquin_L_
Beginner
412 Views

I've got reasons to believe (but couldn't check directly) that the following program

#include <iostream>
#include <initializer_list>

struct foo
{
  template<typename... Args>
  foo(Args&&...){std::cout<<"int ctor\n";}
  foo(std::initializer_list<int>){std::cout<<"init-list ctor\n";}
};

int main()
{
  foo x{1};
}


will output "int ctor" rather than "init-list ctor" (which is the right output) in Intel 14.01. Could some with access to the compiler check this out? Thank you!

 

Joaquín M López Muñoz

Telefónica Digital

 

0 Kudos
4 Replies
JenniferJ
Moderator
412 Views

On Windows, the header "initializer_list" comes with VS2013. so you will need the VS2013 in order to compiler this code. The Intel C++ Compiler 14.0 update 1 supports VS2013, and it compiles this code fine:

C:\temp>type init.cpp
#include <iostream>
 #include <initializer_list>

struct foo
 {
   template<typename... Args>
   foo(Args&&...){std::cout<<"int ctor\n";}
   foo(std::initializer_list<int>){std::cout<<"init-list ctor\n";}
 };

int main()
 {
   foo x{1};
 }

C:\temp>
C:\temp>icl /c init.cpp
Intel(R) C++ Compiler XE for applications running on IA-32, Version 14.0.1.139 Build 20131008
Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

init.cpp

C:\temp>icl /c init.cpp

0 Kudos
Joaquin_L_
Beginner
412 Views

Hi Jennifer,

Can you pleasee run the resulting executable and report back its output. I think it's going to be "int ctor" rather than "init-list ctor", which would indicate a problem with the compiler's support of initializer_lists.

Thank you,

Joaquín M López Muñoz
Telefónica Digital

0 Kudos
JenniferJ
Moderator
412 Views

I got the answer as following:

C:\temp>init
init-list ctor

C:\temp>

 

0 Kudos
Joaquin_L_
Beginner
412 Views

How weird, I've distilled this down from a more complex scenario where such a bug seemed to be occuring. Thank you!

Joaquín M López Muñoz
Telefónica Digital

0 Kudos
Reply