<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 --- - Clang fails to build Qt applications using a foreach convenience macro"
href="http://llvm.org/bugs/show_bug.cgi?id=17650">17650</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang fails to build Qt applications using a foreach convenience macro
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</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++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>tobias.hunger@gmail.com
</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>Qt offers a convenience macro called foreach to iterate over values of a list,
etc. This expands to the following:
for (QForeachContainer<__typeof__(m_components)> _container_(m_components);
!_container_.brk && _container_.i != _container_.e; __extension__ ({
++_container_.brk; ++_container_.i; })) for (QObject *component =
*_container_.i;; __extension__ ({--_container_.brk; break;})) {
Clang will now complain about this with the following error message:
... error: 'break' statement not in loop or switch statement body
which is indeed what is happening. I am not positive whether this is legal C++
or not, but this is used in Qt since before 2011 and has never been a problem
so far on any of the supported platforms.
I assume this is introduced by
<a href="https://llvm.org/svn/llvm-project/cfe/trunk@193073">https://llvm.org/svn/llvm-project/cfe/trunk@193073</a>
which removes a test case similar to what is used in Qt from the
trunk/test/Analysis/dead-stores.c. That commit message claims that GCC rejects
this, but it does not using gcc <= 4.8.1.
Please reintroduce this behavior (or at least provide a switch to turn it off)
to avoid breaking the build of (almost) *all* Qt applications in existence
using clang.
Yes, we should fix Qt to not do this, but we can not retro-actively fix all the
Qt sources out there and people will encounter this issue when building any Qt
source code with clang.
Also note that <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - Miscompilation of Qt foreach macro"
href="show_bug.cgi?id=7189">http://llvm.org/bugs/show_bug.cgi?id=7189</a> fixes the Qt foreach
macro, so there was work done to introduce this behavior in the first place.</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>