Home Dashboard Directory Help
Search

C99 compound literals problem by fplgenius


Status: 

Closed
 as By Design Help for as By Design


2
0
Sign in
to vote
Type: Bug
ID: 800984
Opened: 9/16/2013 11:28:31 AM
Access Restriction: Public
0
Workaround(s)
view
0
User(s) can reproduce this bug

Description

Visual Studio 2013 rc has problems with C99 compound literals.

Example code:
    int ia[] = (int []) { 10,20,30 };

This simple code does NOT work.
Details
Sign in to post a comment.
Posted by fplgenius on 9/28/2013 at 12:25 AM
Yep, now that I read about fully I realize that, thanks:
Issue is closed.
Posted by Microsoft on 9/25/2013 at 8:40 AM
The code as posted is using compound literals, which won't compile in C++ at all, as compound literals are a C99 feature.
We added support for C99 compound literals in the C compiler for Dev12, however the example provided is not legal according to the standard.

int ia[] = (int[]) { 10, 20, 30 };

The reason your example does not compile can be found in 6.7.8 of the spec. Specifically look at 12-16. Note (an array is of aggregate type).

Clause 13 allows structs/unions to be initialized with a single expression of compatible type, but this is not specified for arrays. Clauses 14 and 15 contain some special rules for arrays of character type and string literals.

Clause 16 is this:

16) Otherwise, the initializer for an object that has aggregate or union type shall be a brace- enclosed list of initializers for the elements or named members.

This may be easier to see with the following example, which is not allowed either. A compound literal creates an unnamed variable, which is semantically the same as the following.

int arr1[] = {1,2,3};
int arr2[] = arr1;
Posted by UnitUniverse on 9/20/2013 at 6:47 AM
oh i almost forgot: The C99-only(the part of C std which the C++ std isn't compatible with) won't be supported in VC(At least there is no relevant plan yet).
Posted by Microsoft on 9/20/2013 at 3:40 AM
Thanks for your quick response. Your issue has been routed to the appropriate VS development team for investigation. We will contact you if we require any additional information.
Posted by fplgenius on 9/20/2013 at 12:49 AM
The problem is with "compile as" conventions i.e. /TC and /TP that says "Compile as C code" and "Compile as Cpp code".
When I do work in C I always set my convention to /TC and for Cpp I set it to normally /TP.
When I set it to Cpp I get the same errors as you all.
Cheers I sent you the pictures with both set separatelly.
Posted by Microsoft on 9/19/2013 at 10:47 PM
The screenshot has been attached, please see it.
Posted by Microsoft on 9/19/2013 at 10:46 PM
Hi fplgenius,

Thanks for your feedback. According to the information you have provieded, we run the code no more than ten times, but still couldn't get the error C2075. we got the same result as UnitUniverse described: error C2059, error C2143, error C2143. We have attached the screenshot, please check it. We don't know whether you have set something in your project. So could you please give us a complete demo project and a screenshot so that we can conduct further research?

We look forward to hearing from you with this information.
Posted by fplgenius on 9/18/2013 at 11:18 AM
@UnitUniverse yep It's Visual Studio Professional RC version 12.0.20827.3 DP
I don't know anything about MFC but include stdio and stdlib and you will see the same as me.
Whats weird is that with pointers it WORKS, example:

int *p = (int i[]) { 10,20,30};
This code DOES WORK, so apparently Microsft has some isues with arrays in compund literals.
Posted by UnitUniverse on 9/17/2013 at 9:50 AM
It's weird...
I got many more(and differ) compiling errors.
1>e:\consoleapplication1\consoleapplication1\consoleapplication1.cpp(9): error C2059: syntax error : '{'
1>e:\consoleapplication1\consoleapplication1\consoleapplication1.cpp(9): error C2143: syntax error : missing ';' before '{'
1>e:\consoleapplication1\consoleapplication1\consoleapplication1.cpp(9): error C2143: syntax error : missing ';' before '}'

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"


int _tmain(int /*argc*/, _TCHAR * /*argv*/[])
{
    int ia[] = (int[]) { 10, 20, 30 };

    return 0;
}

@fplgenius : What version do you have? Are you sure it is the RC version?
Posted by Microsoft on 9/17/2013 at 12:35 AM
Hello,

Thanks for your feedback. According to the information you have provided, when we run the code, we couldn't get the error C2075. In order to efficiently investigate and reproduce this issue, could you please give us a demo project?

We look forward to hearing from you with this information.
Posted by Microsoft on 9/16/2013 at 11:51 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(http://support.microsoft.com)
Sign in to post a workaround.
File Name Submitted By Submitted On File Size  
ConsoleApplication1.cpp 9/17/2013 218 bytes
file.txt 9/18/2013 198 bytes
file.txt 9/18/2013 198 bytes
file.txt 9/18/2013 198 bytes
main.cpp 9/18/2013 201 bytes
test.png 9/19/2013 119 KB
Cpp11_TP.png (restricted) 9/20/2013 -
Cpp11_TC.png (restricted) 9/20/2013 -