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

Uniform Initialization and default constructor arguments in C++11

Alexander__D_
Beginner
620 Views

Hi ! First of all, big Kudos to Intel for supporting Educational Community !!!

I wrote small program to try out new feature in C+11 - Uniform Initialization. However, getting a lot of errors and one incorrect result.
(Basically, I am following http://www.informit.com/articles/article.aspx?p=1852519)
Using Visual Studio 2012(latest) with Intel C++ Compiler 13(latest). C++0x support enabled.

#include <iostream>
#include <string>
#include <vector>
#include <map>
using namespace std;

class C {
public:

    C(int a = 1, int b = 2) : n{0,1,2,3,4}, a_{a}, b_{b} {};
    int n[5];
    int a_,b_;

};

int main()
{
    C c = C{}; // OK
    C *p = new C; // OK
    //C *p2 = new C{}; // Does not compile

    cout << c.a_ << "  " << c.b_ << endl; // Getting "0 0" instead of  "1 2"

    int var{0}; // OK
    string s{"hello"}; // OK
    string s2{s}; // OK copy constructor
    //vector<string> vs{"alpha", "betta", "gamma"}; // Does not compile
    //double *pd= new double [3] {0.5, 1.2, 12.99}; // Does not compile

    //int n{}; // Does not compile
    //int *p{}; // Does not compile
    //char s[12]{}; // Does not compile
    //string s{}; // Does not compile
    //char *p=new char [5]{};
    return 0;
}

Thanks !

0 Kudos
3 Replies
Judith_W_Intel
Employee
620 Views

 

Please upgrade to Intel compiler 14.0... version13.0 was released well before MSVC++ 2012 existed.

When I uncomment the lines in your example and compile with 14.0 and VS 2012 I see these expected errors:

19% icl /Qstd=c++11 -c t.cpp
Intel(R) C++ Compiler XE for applications running on IA-32, Version 14.0 Beta Bu
ild x
Built Aug 15 2013 22:00:50 by jward4 on JWARD4-DESK in D:/workspaces/14_0cfe/dev

Copyright (C) 1985-2013 Intel Corporation.  All rights reserved.

t.cpp
t.cpp(27): error: no instance of constructor "std::vector<_Ty, _Alloc>::vector [
with _Ty=std::string, _Alloc=std::allocator<std::string>]" matches the argument
list
            argument types are: (const char [6], const char [6], const char [6])

      vector<string> vs{"alpha", "betta", "gamma"}; // Does not compile
                       ^

t.cpp(31): error: "p" has already been declared in the current scope
      int *p{}; // Does not compile
           ^

t.cpp(32): error: "s" has already been declared in the current scope
      char s[12]{}; // Does not compile
           ^

t.cpp(33): error: "s" has already been declared in the current scope
      string s{}; // Does not compile
             ^

t.cpp(34): error: "p" has already been declared in the current scope
      char *p=new char [5]{};
            ^

compilation aborted for t.cpp (code 2)

Note the first error is because the MSVC++ 2012 standard library headers do not yet have std::initializer_list constructors.

Judy

0 Kudos
Alexander__D_
Beginner
620 Views

Judith, thank you for replying !!

I downloaded Beta Version 13 SP1 (I guess stable release is 13.0) and tested once again.
Most of the stuff worked fine. However, I am also getting two errors for two lines:

//double *pd= new double [3]{0.5, 1.2, 12.99}; // Does not compile
// char *p3=new char [5]{}; // Does not compile

Both produce idential error:

1>------ Build started: Project: Virtual Functions (Intel C++ 14.0), Configuration: Debug Win32 ------
1>  Source.cpp
1>" : error : backend signals
1>  
1>  compilation aborted for Source.cpp (code 4)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

-Alexander

0 Kudos
Judith_W_Intel
Employee
620 Views

Alexander,

I can reproduce the internal error in our development compiler. I created a new defect report for it (DPD200247538). Thanks for reporting it to us ... it seems to be caused by aggregate initialization of array types. We will fix it as soon as possible.

thanks again,

Judy

0 Kudos
Reply