<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - Different results between gcc and clang when compiling a rather simple c++11 program"
href="http://llvm.org/bugs/show_bug.cgi?id=18177">18177</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Different results between gcc and clang when compiling a rather simple c++11 program
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>3.3
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>MacOS X
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++11
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>cilio.c@email.it
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=11688" name="attach_11688" title="Short, Self Contained, Correct (Compilable), Example">attachment 11688</a> <a href="attachment.cgi?id=11688&action=edit" title="Short, Self Contained, Correct (Compilable), Example">[details]</a></span>
Short, Self Contained, Correct (Compilable), Example
I'm trying to understand whether the different behavior exposed by gcc vs.
clang in the output of this simple C++11 program is due to a bug in clang
(Xcode 5.0.2, OS X 10.8.5). The code is as follows:
#include <iostream>
int main() {
int matrix[][3]{{1,2,3}, {4,5,6}, {7,8,9}};
auto dyn_matrix = new int[3][3]{{1,2,3}, {4,5,6}, {7,8,9}};
std::cout << matrix[0][1] << std::endl;
std::cout << dyn_matrix[0][1] << std::endl;
return 0;
}
As shown, I'm trying to use uniform initialization to initialize an anonymous
(resp. named) multidimensional array of size 3x3. When compiling with gcc 4.7
from MacPorts the expected output is obtained:
$g++-mp-4.7 -std=c++11 dyn_matrix.cpp -o dyn_matrix
$ ./dyn_matrix
2
2
$
Conversely, in case clang is used the output reads:
$ clang++ -std=c++11 -stdlib=libc++ dyn_matrix.cpp -o dyn_matrix_clang
$ ./dyn_matrix_clang
2
4
$
In this case the result is (apparently) wrong. clang --version reports:
Apple LLVM version 5.0 (clang-500.2.75) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin12.5.0
Thread model: posix
I've also tried with clang 3.4 (trunk 187030). In that case clang crashes when
trying to compile that code.
Thanks.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>