[llvm-bugs] [Bug 33929] New: -Wcast-qual should not warn about dropping 'const' when casting to ObjC types

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Jul 25 11:59:53 PDT 2017


            Bug ID: 33929
           Summary: -Wcast-qual should not warn about dropping 'const'
                    when casting to ObjC types
           Product: clang
           Version: trunk
          Hardware: All
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: jordan_rose at apple.com
                CC: llvm-bugs at lists.llvm.org

// clang -fsyntax-only -x objective-c -Weverything -
id reinterpretAsObject(const void *ptr) {
  return (id)ptr;

<stdin>:2:14: warning: cast from 'const void *' to 'id' drops const qualifier
  return (id)ptr;

...however, there's no way to avoid this warning; you can't const-qualify
Objective-C object types inside the pointer. It might have been better if this
weren't a common idiom on Apple platforms, but it is---both 'const void *' and
opaque pointers to const struct types are sometimes valid Objective-C objects,
and casts to 'id', 'Class', or concrete object pointer types like 'NSString *'
are considered common and acceptable.

(If we /were/ to start warning on these all the time, they should be silenced
by adding '__bridge', and the warning should have a fix-it. But even that's
probably too much churn for Apple platforms.)

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/20170725/53bc9091/attachment.html>

More information about the llvm-bugs mailing list