[llvm-bugs] [Bug 37350] New: Old cast warning in Extern "C" code.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 7 06:15:12 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37350

            Bug ID: 37350
           Summary: Old cast warning in Extern "C" code.
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: francois.budin at kitware.com
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org

Created attachment 20268
  --> https://bugs.llvm.org/attachment.cgi?id=20268&action=edit
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:
https://gcc.gnu.org/ml/gcc-patches/1999-07n/msg00229.html

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]
https://github.com/llvm-project/llvm-project-20170507/blob/master/clang/lib/Sema/SemaExpr.cpp#L6144-L6146
[2] clang++ -v -Wold-style-cast main.cxx

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180507/3a5fc526/attachment-0001.html>


More information about the llvm-bugs mailing list