Problem with initializer list

Problem with initializer list

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

 

5 posts / novo 0
Último post
Para obter mais informações sobre otimizações de compiladores, consulte Aviso sobre otimizações.

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

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

I got the answer as following:

C:\temp>init
init-list ctor

C:\temp>

 

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

Faça login para deixar um comentário.