Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 713603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:58:47+00:00 2026-05-14T04:58:47+00:00

Is this list-initialization of an array of unknown size valid in C++0x? int main()

  • 0

Is this list-initialization of an array of unknown size valid in C++0x?

int main() { int x[]{0, 1,2,3,4}; return x[0]; }

I believe it is valid, but would appreciate some confirmation.

If anyone could quote from the C++0x-FCD to support their case, it would be greatly appreciated.

Thanks!

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T04:58:48+00:00Added an answer on May 14, 2026 at 4:58 am

    This goes from 8.5/16 first bullet to 8.5.4 list-initialization and from 8.5.4/3 third bullet to 8.5.1 aggregate initialization and then 8.5.1/4 says

    An array of unknown size initialized with a brace-enclosed initializer-list containing n initializer-clauses, where shall be greater than zero, is defined as having elements

    The only difference if the object is an array between = { ... } and { ... } is that the first is called copy-list-initialization and the second is called direct-list-initialization, so both are kinds of list-initialization. The elements of the array are copy-initialized from the elements of the initializer list in both cases.

    Notice that there is a subtle difference between those forms if the array has a size and the list is empty, in which case 8.5.4 second bullet applies:

    struct A {
      explicit A();
    };
    
    A a[1]{};    // OK: explicit constructor can be used by direct initialization
    A a[1] = {}; // ill-formed: copy initialization cannot use explicit constructor
    

    This difference does not apply to lists that have content in which case third bullet applies again, though

    struct A {
      explicit A(int);
    };
    
    A a[1]{0};    // ill-formed: elements are copy initialized by 8.5.1
    A a[1] = {0}; // ill-formed: same.
    

    The FCD changed this compared to the previous draft, and initialization with an empty initializer list now always works even with explicit default constructors. This is because the FCD states that the elements are value-initialized, and value initialization doesn’t care about explicitness since it doesn’t do overload resolution on default constructors (it couldn’t figure out better or worse matches anyway). The previous draft used normal overload resolution on the constructors and thus rejected explicit default constructors during copy initialization. This defect report did that change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a collection like this List<int> {1,15,17,8,3}; how to get a flat string
The comma , items separator used in an array initialization list may end the
I'd like to use a generic list, but the initialization method only returns a
Is it stable to use something like this in a class's ctor initialization list
In C++, it's not possible to initialize array members in the initialization list, thus
Hello I have this list that i am working on. When i move the
Actually I have this list Directory where I am adding the name of the
My application uses a list like this: List<MyClass> list = new List<MyClass>(); Using the
Take this table WORDS WORD Hello Aardvark Potato Dog Cat And this list: ('Hello',
I am trying to do this: List<Parent> test = new List<Child>(); The complete code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.