Go to file
Tor Arne Vestbø 0f39fc55c9 Forward declare Objective-C classes as class, not typedef objc_object
Forward declaring an Objective-C class in Objective-C/C++ mode is done
by using the `@class` syntax, e.g.:

  @class NSString;

In C/C++ mode however there's no documented approach, so we chose
to flatten the type down to the opaque objc_object "base class":

  typedef struct objc_object NSString;

As it turns out, when Objective-C classes are used as arguments or return
types in C++, the signature they produce is equal to what it would have
been if the type was a normal class. For example:

  void foo(NSString *) -> __Z3fooP8NSString

The is due to @class in Objective-C++ just being just sugar, so an NSString
pointer is not treated as `struct objc_object *` but rather a pointer to a
distinct type, which then gets mangled as such by LLVM's Itanium mangler
in CXXNameMangler::mangleType(const ObjCObjectType *T).

With our current forward declaration however, we are expecting:

  void foo(NSString *) -> __Z3fooP11objc_object

As a consequence exported helper functions such as QString::fromNSString()
are not possible to use from plain C++ right now, as it will give a linker
error for the missing QString::fromNSString(objc_object*) function.

And even if we did define the extra signature, it would not be possible
to declare overloaded functions taking Objective-C classes, as they would
all produce ambiguous overloads in C++ mode.

To fix this we change the forward declaration to a plain old class,
which matches the signature in both Objective-C++ and plain C++ mode,
and allows overloads. This is a binary compatible change, as no client
were using any of these functions from C++ anyways as they would have
produced linker errors. It does have a slight source compatible break,
for clients that manually forward declared classes using the old style,
but that use-case is deemed fringe enough to accept, and clients can
work around this by defining Q_FORWARD_DECLARE_OBJC_CLASS to their
preferred format, which Qt will respect.

Pick-to: 6.2
Change-Id: I04813c60a7da22379dd9de1be56cc12c53a38232
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
2021-08-17 02:55:12 +02:00
.github/workflows Github Actions: many minor updates 2021-01-22 18:48:54 +01:00
bin CMake: Allow usage of QtStandaloneTestTemplateProject as package component 2021-04-23 13:31:04 +02:00
cmake CMake: Warn if qt_internal_plugin(target) does not end with 'Plugin' 2021-08-12 12:43:49 +02:00
coin Apply custom timeouts to cross compilations 2021-08-10 12:21:58 +00:00
config.tests Fix the precompile_header configure test 2021-06-19 01:08:23 +02:00
dist Add Qt 6.0.0 changes file 2020-11-16 10:02:08 +02:00
doc Doc: Terminate C-comment 2021-06-30 13:36:26 +02:00
examples Improve translations loading code in standarddialogs example 2021-08-06 17:08:10 +02:00
lib Purge all fonts 2015-08-18 19:59:14 +00:00
libexec Fix global header exclusion regex 2021-07-09 13:56:18 +02:00
mkspecs Fix location of qtattributionsscanner 2021-07-14 18:16:15 +02:00
qmake Avoid to call _qt_internal_set_up_static_runtime_library() twice 2021-08-03 04:18:42 +08:00
src Forward declare Objective-C classes as class, not typedef objc_object 2021-08-17 02:55:12 +02:00
tests QUrl: Improve Punycode overflow handling 2021-08-16 19:47:14 +00:00
util CMake: Bump project versions 2021-08-02 12:42:29 +02:00
.cmake.conf CMake: Bump min required CMake version for static Qt builds to 3.21 2021-08-10 16:51:53 +02:00
.gitattributes Give batch files CRLF line endings 2020-11-04 15:02:29 +00:00
.gitignore testlib: Accurately name JUnit test, and only run for JUnitXML reporter 2021-07-29 15:39:40 +02:00
.lgtm.yml Skip LGTM analysis for the bootstrap library and tools 2020-07-16 01:04:34 +02:00
.qmake.conf Bump version 2021-02-18 07:20:21 +02:00
.tag Update the git-archive export options 2012-09-07 15:39:31 +02:00
CMakeLists.txt CMake: Enforce minimum CMake version in user projects 2021-08-04 16:03:08 +02:00
conanfile.py Conan: simplify Conan recipe 2021-06-21 15:19:16 +03:00
config_help.txt Remove dysfunctional -coverage configure argument 2021-08-10 12:00:13 +02:00
configure Remove unsupported, host-related options from configure shell script 2021-08-05 02:44:27 +02:00
configure.bat Remove superfluous variable assignments from configure.bat 2021-03-11 16:39:54 +01:00
configure.cmake Remove dysfunctional -coverage configure argument 2021-08-10 12:00:13 +02:00
dependencies.yaml Re-add dependencies.yaml now that qt5.git wip/qt6 builds fine 2019-09-18 13:19:31 +02:00
LICENSE.FDL
LICENSE.GPL2 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPL3 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.GPL3-EXCEPT Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.LGPL3 Add new license header templates and license files 2016-01-14 20:43:46 +00:00
LICENSE.LGPLv3 Remove LICENSE.GPLv3, LICENSE.LGPLv21, LGPL_EXCEPTION.txt 2018-04-16 11:02:14 +00:00
LICENSE.QT-LICENSE-AGREEMENT Update enterprise license agreement v4.2.1 2019-12-18 13:07:19 +02:00
qt_cmdline.cmake Remove dysfunctional -coverage configure argument 2021-08-10 12:00:13 +02:00
sync.profile Implement generating of a module cpp export header 2021-06-24 20:40:49 +02:00