Note that there are some explanatory texts on larger screens.

plurals
  1. PODifferent results between gcc and clang when compiling a rather simple c++11 program
    primarykey
    data
    text
    <p>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:</p> <pre><code>#include &lt;iostream&gt; 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 &lt;&lt; matrix[0][1] &lt;&lt; std::endl; std::cout &lt;&lt; dyn_matrix[0][1] &lt;&lt; std::endl; return 0; } </code></pre> <p>As shown, I'm trying to use uniform initialization to initialize an anonymous (resp. named) multidimensional array of size <code>3x3</code>. When compiling with gcc 4.7 from MacPorts the expected output is obtained:</p> <pre><code>$g++-mp-4.7 -std=c++11 dyn_matrix.cpp -o dyn_matrix $ ./dyn_matrix 2 2 $ </code></pre> <p>Conversely, in case clang is used the output reads:</p> <pre><code>$ clang++ -std=c++11 -stdlib=libc++ dyn_matrix.cpp -o dyn_matrix_clang $ ./dyn_matrix_clang 2 4 $ </code></pre> <p>In this case the result is (apparently) wrong. <code>clang --version</code> reports:</p> <pre><code>Apple LLVM version 5.0 (clang-500.2.75) (based on LLVM 3.3svn) Target: x86_64-apple-darwin12.5.0 Thread model: posix </code></pre> <p>Who's to blame? me, gcc or clang?</p> <p><strong>UPDATE Dec 11th, 2013:</strong> The bug should have been fixed in r196995. Unfortunately, we still do not know how long it will take before Apple updates the version of clang that ships with Xcode. </p> <p><strong>UPDATE Dec 9th, 2013:</strong> I submitted a bug report on the LLVM bugzilla platform. It has indeed been recognized as a bug, a patch is currently under review, see <a href="http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20131209/095099.html" rel="noreferrer">http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20131209/095099.html</a>. </p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload