<html>
<head>
<base href="https://bugs.llvm.org/">
</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 - Old cast warning in Extern "C" code."
href="https://bugs.llvm.org/show_bug.cgi?id=37350">37350</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Old cast warning in Extern "C" code.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>francois.budin@kitware.com
</td>
</tr>
<tr>
<th>CC</th>
<td>dgregor@apple.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Created <span class=""><a href="attachment.cgi?id=20268" name="attach_20268" title="Simple C++ code to reproduce the warning.">attachment 20268</a> <a href="attachment.cgi?id=20268&action=edit" title="Simple C++ code to reproduce the warning.">[details]</a></span>
Simple C++ code to reproduce the warning.
The bug I found is a warning that should not be thrown, and is not thrown with
GCC.
When compiling a piece of code that is inside an -- extern "C" -- statement,
and that contains a C-style casting, clang throws an old style cast warning (or
error if the -Werror flag is used). But since it is inside a section of code
that is declared as C, I don't think that there should be any warning.
Note that GCC does not throw this warning when compiling the same piece of
code. I found a link to a patch proposed a long time ago for GCC to solve that
same bug. I did not explore GCC's code to see if that exact patch had been
merged or if this problem had been solved in a different way. For reference,
here is the discussion I found about the same bug for GCC:
<a href="https://gcc.gnu.org/ml/gcc-patches/1999-07n/msg00229.html">https://gcc.gnu.org/ml/gcc-patches/1999-07n/msg00229.html</a>
Note that this bug is reproducible with the latest compilation of clang.
A simple way to reproduce this problem is to try to compile the code attached.
Thanks,
Francois
----------------------------------------------------------------------------------------
Command line to run:
----------------------------
Note that this command line is the sub-command line that actually produces the
problem and allows to add a break point where the warning is thrown [1]. One
could run a simple compilation command line [2] and get the warning, but it is
more difficult to debug as the warning appears in a compilation sub-process in
that case.
Note also that {clang_build} should be replaced by the directory in which clang
is built, and ${test_directory} should be replaced by where `main.cxx` is
saved.
clang-7 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all
-disable-free -main-file-name main.cxx -mrelocation-model static -mthread-model
posix -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases
-munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info
-debugger-tuning=gdb -v -resource-dir ${clang_build}/lib/clang/7.0.0
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0
-internal-isystem
/usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward
-internal-isystem /usr/local/include -internal-isystem
${clang_build}/lib/clang/7.0.0/include -internal-externc-isystem
/usr/include/x86_64-linux-gnu -internal-externc-isystem /include
-internal-externc-isystem /usr/include -Wold-style-cast -fdeprecated-macro
-fdebug-compilation-dir ${test_directory} -ferror-limit 19 -fmessage-length 204
-fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option
-fcolor-diagnostics -o /tmp/main-d474b2.o -x c++ main.cxx
Output
---------
main.cxx:6:10: warning: use of old-style cast [-Wold-style-cast]
return (float)i;
^ ~
1 warning generated.
--------------------------------------------------------------------
[1]
<a href="https://github.com/llvm-project/llvm-project-20170507/blob/master/clang/lib/Sema/SemaExpr.cpp#L6144-L6146">https://github.com/llvm-project/llvm-project-20170507/blob/master/clang/lib/Sema/SemaExpr.cpp#L6144-L6146</a>
[2] clang++ -v -Wold-style-cast main.cxx</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>