-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Full name of submitter: Anoop Rana
Reference (section label): [dcl.init.general]
Link to reflector thread (if any):
Issue description: The statement std::string arr[] = "some string";
seems to be allowed by the dcl.init.general#16.5. We observe implementation divergence here.
#include <string>
int main()
{
std::string arr[] = "some string"; //msvc accepts but clang and gcc rejects(as expected)
}
In C++ 17 this was not allowed as per dcl.init#17.5 which used to say "Otherwise, if the destination type is an array, the program is ill-formed. " but in C++20 this was changed to dcl.init.general#16.5 to say:
Otherwise, if the destination type is an array, the object is initialized as follows.. Let x1, …, xk be the elements of the expression-list. If the destination type is an array of unknown bound, it is defined as having k elements.. Let n denote the array size after this potential adjustment.. If k is greater than n, the program is ill-formed.. Otherwise, the ith array element is copy-initialized with xi for each 1 ≤ i ≤ k, and value-initialized for each k<i≤n.. For each 1≤i<j≤n, every value computation and side effect associated with the initialization of the ith element of the array is sequenced before those associated with the initialization of the jth element.
Suggested resolution:
This should be made ill-formed again. Change dcl.init.general#16.5 as indicated:
Otherwise, if the destination type is an array and the initialization is direct-initialization, the object is initialized as follows.. Let x1, …, xk be the elements of the expression-list. If the destination type is an array of unknown bound, it is defined as having k elements.. Let n denote the array size after this potential adjustment.. If k is greater than n, the program is ill-formed.. Otherwise, the ith array element is copy-initialized with xi for each 1 ≤ i ≤ k, and value-initialized for each k<i≤n.. For each 1≤i<j≤n, every value computation and side effect associated with the initialization of the ith element of the array is sequenced before those associated with the initialization of the jth element.
Also add a separate bullet point after dcl.init.general#16.5 saying:
Otherwise, if the destination type is an array and the initialization is copy-initialization, the program is ill-formed.