[Development] On the use of the inline keyword

Cristian Adam cristian.adam at qt.io
Fri Aug 25 13:11:16 CEST 2023


The other way of fixing this is by using ... macros. The article at c++ - Importing inline functions in MinGW - Stack Overflow<https://stackoverflow.com/questions/11546403/importing-inline-functions-in-mingw>  mentions using inline in the class declaration.

Their example works fine with both GCC MinGW and Clang MinGW. Visual C++ is also fine:

#ifdef _WIN32
#define Q_EXPORT_INLINE inline
#else
#define Q_EXPORT_INLINE
#endif


class __declspec(dllimport) MyClass {
public:
    Q_EXPORT_INLINE int myFunc2();
    Q_EXPORT_INLINE int myFunc1();
};

inline int MyClass::myFunc2(void) {
    return myFunc1();
}

inline int MyClass::myFunc1(void) {
    return 0;
}

Cheers,
Cristian

________________________________
From: Development <development-bounces at qt-project.org> on behalf of Kai Köhne via Development <development at qt-project.org>
Sent: Friday, August 25, 2023 11:28
To: development at qt-project.org <development at qt-project.org>; Hasselmann Mathias <mathias at taschenorakel.de>
Subject: Re: [Development] On the use of the inline keyword

Not an GCC expert, but this is the code that emits the warning in GCC:

https://github.com/gcc-mirror/gcc/blob/66be6ed81f369573824f1a8f5a3538a63472292f/gcc/attribs.cc#L1818

First argument for warning() is 0 ... which explains why it cannot be easily disabled with say -Wno-ignored-attributes.

I therefore don't see an easy way to disable this specific warning.

Regards

________________________________________
From: Development <development-bounces at qt-project.org> on behalf of Hasselmann Mathias via Development <development at qt-project.org>
Sent: Friday, August 25, 2023 10:34
To: development at qt-project.org
Subject: Re: [Development] On the use of the inline keyword

Am 24.08.2023 um 21:42 schrieb Thiago Macieira:

> That warning looks like a bug in the compiler instead. So if there's no ill-
> effect, I'd just disable and ignore it.

Seems like an easy fix, but breaks user code that explicitly enables
this warning. Guess ignoring is not a good option, if one cares about
user experience.

Ciao
Mathias

--
Development mailing list
Development at qt-project.org
https://lists.qt-project.org/listinfo/development
--
Development mailing list
Development at qt-project.org
https://lists.qt-project.org/listinfo/development
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20230825/3617ac49/attachment.htm>


More information about the Development mailing list