clang (c++11) compiler fails to compile static const QStringList deleteFilesList = #3685

Closed
opened 2026-02-21 16:54:32 -05:00 by deekerman · 28 comments
Owner

Originally created by @yurivict on GitHub (Jan 6, 2016).

These lines:

    static const QStringList deleteFilesList = {
        // Windows
        "Thumbs.db",
        "desktop.ini",
        // Linux
        ".directory",
        // Mac OS
        ".DS_Store"
    };

cause an error with clang-3.4.1:

compiling base/utils/fs.cpp
base/utils/fs.cpp:125:30: error: no matching constructor for initialization of 'const QStringList'
    static const QStringList deleteFilesList = {

Happens with both qt4 and qt5.

This might be implicitly using some gcc extension. Not sure.

You might want to remove the (possibly non-standard) constructor, and only delete based on the platform (with ifdefs). Or just list them all explicitly.

Originally created by @yurivict on GitHub (Jan 6, 2016). These lines: ``` static const QStringList deleteFilesList = { // Windows "Thumbs.db", "desktop.ini", // Linux ".directory", // Mac OS ".DS_Store" }; ``` cause an error with clang-3.4.1: ``` compiling base/utils/fs.cpp base/utils/fs.cpp:125:30: error: no matching constructor for initialization of 'const QStringList' static const QStringList deleteFilesList = { ``` Happens with both qt4 and qt5. This might be implicitly using some gcc extension. Not sure. You might want to remove the (possibly non-standard) constructor, and only delete based on the platform (with ifdefs). Or just list them all explicitly.
Author
Owner

@Chocobo1 commented on GitHub (Jan 7, 2016):

Does removing static keyword fix the error? (probably not. BTW, I see no reason of using it)

@Chocobo1 commented on GitHub (Jan 7, 2016): Does removing `static` keyword fix the error? (probably not. BTW, I see no reason of using it)
Author
Owner

@yurivict commented on GitHub (Jan 7, 2016):

No, static has nothing to do with this.

@yurivict commented on GitHub (Jan 7, 2016): No, static has nothing to do with this.
Author
Owner

@Chocobo1 commented on GitHub (Jan 7, 2016):

What about your Qt version?

@Chocobo1 commented on GitHub (Jan 7, 2016): What about your Qt version?
Author
Owner

@yurivict commented on GitHub (Jan 7, 2016):

I tried both 4.8.7 and 5.4.1

@yurivict commented on GitHub (Jan 7, 2016): I tried both 4.8.7 and 5.4.1
Author
Owner

@glassez commented on GitHub (Jan 7, 2016):

clang supports initializer lists starting from version 3.1 (See http://clang.llvm.org/cxx_status).
Maybe you forgot to use -std=c++11 when you built Qt? Or maybe Qt incorrectly determines the capabilities of your compiler?.. Unfortunately, it happens. Try to explicitly define Q_COMPILER_INITIALIZER_LISTS.

@glassez commented on GitHub (Jan 7, 2016): **clang** supports initializer lists starting from version 3.1 (See http://clang.llvm.org/cxx_status). Maybe you forgot to use -std=c++11 when you built Qt? Or maybe Qt incorrectly determines the capabilities of your compiler?.. Unfortunately, it happens. Try to explicitly define Q_COMPILER_INITIALIZER_LISTS.
Author
Owner

@yurivict commented on GitHub (Jan 7, 2016):

My compiler is clang 3.4.1

FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512

Command line does include -std=c++11.
And it doesn't matter how Qt itself was compiled, as this is the compile-time error we are talking about. Qt doesn't determine any compiler capabilities here.

@yurivict commented on GitHub (Jan 7, 2016): My compiler is clang 3.4.1 ``` FreeBSD clang version 3.4.1 (tags/RELEASE_34/dot1-final 208032) 20140512 ``` Command line does include -std=c++11. And it doesn't matter how Qt itself was compiled, as this is the compile-time error we are talking about. Qt doesn't determine any compiler capabilities here.
Author
Owner

@naikel commented on GitHub (Jan 7, 2016):

It is a Qt problem. Qt has to be rebuilt with CONFIG += c++11 in qt.pro.

Please don't do things like QMAKE_CXXFLAGS += -std=c++11. That would be insufficient.

It's a common problem and very well documented all over the Internet.

@naikel commented on GitHub (Jan 7, 2016): It is a Qt problem. Qt has to be rebuilt with CONFIG += c++11 in qt.pro. Please don't do things like QMAKE_CXXFLAGS += -std=c++11. That would be insufficient. It's a common problem and very well documented all over the Internet.
Author
Owner

@naikel commented on GitHub (Jan 7, 2016):

Also:

And it doesn't matter how Qt itself was compiled, as this is the compile-time error we are talking about. Qt doesn't determine any compiler capabilities here.

If you read the error a little it says that Qt didn't include that constructor for C++11. That's why it fails. If you recompile Qt properly the constructor will be included, and the program will compile successfully.

Remember this is Object Oriented Programming. Anything that has an object and an equal sign just after it needs a constructor. This is not plain C.

@naikel commented on GitHub (Jan 7, 2016): Also: > And it doesn't matter how Qt itself was compiled, as this is the compile-time error we are talking about. Qt doesn't determine any compiler capabilities here. If you read the error a little it says that Qt didn't include that constructor for C++11. That's why it fails. If you recompile Qt properly the constructor will be included, and the program will compile successfully. Remember this is Object Oriented Programming. Anything that has an object and an equal sign just after it needs a constructor. This is not plain C.
Author
Owner

@yurivict commented on GitHub (Jan 7, 2016):

Could you please pinpoint how does the qt build factor into the header-only compilation of
qBittorrent? You realize that the failure occurs during the compile-only phase?

@yurivict commented on GitHub (Jan 7, 2016): Could you please pinpoint how does the qt build factor into the header-only compilation of qBittorrent? You realize that the failure occurs during the compile-only phase?
Author
Owner

@naikel commented on GitHub (Jan 7, 2016):

In Qt 4.x you would have to recompile it.

Qt 5.x should support C++11 fully. Try the suggestion above, defining Q_COMPILER_INITIALIZER_LISTS, maybe Qt isn't detecting properly that your compiler needs it.

@naikel commented on GitHub (Jan 7, 2016): In Qt 4.x you would have to recompile it. Qt 5.x should support C++11 fully. Try the suggestion above, defining Q_COMPILER_INITIALIZER_LISTS, maybe Qt isn't detecting properly that your compiler needs it.
Author
Owner

@yurivict commented on GitHub (Jan 7, 2016):

In Qt 4.x you would have to recompile it.

Only headers are used during qbittorent compilation. I don't see how headers depend on the way how qt was compiled.

@yurivict commented on GitHub (Jan 7, 2016): > In Qt 4.x you would have to recompile it. Only headers are used during qbittorent compilation. I don't see how headers depend on the way how qt was compiled.
Author
Owner

@glassez commented on GitHub (Jan 8, 2016):

@yurivict, try add following lines before:

#ifndef Q_COMPILER_INITIALIZER_LISTS
#error Q_COMPILER_INITIALIZER_LISTS is undefined!
#endif

and recompile. What do your compiler say in this case?

@glassez commented on GitHub (Jan 8, 2016): @yurivict, try add following lines before: ``` c++ #ifndef Q_COMPILER_INITIALIZER_LISTS #error Q_COMPILER_INITIALIZER_LISTS is undefined! #endif ``` and recompile. What do your compiler say in this case?
Author
Owner

@glassez commented on GitHub (Jan 8, 2016):

And yet...
@yurivict, what Qt build you use? I assume you're doing a custom build, since there are no official Qt builds for clang.

@glassez commented on GitHub (Jan 8, 2016): And yet... @yurivict, what Qt build you use? I assume you're doing a custom build, since there are no official Qt builds for clang.
Author
Owner

@yurivict commented on GitHub (Jan 8, 2016):

The problem only occurs with Qt4. Qt5 doesn't have this problem.
@glassez the #error Q_COMPILER_INITIALIZER_LISTS is undefined! does get triggered.

It appears that qBittorrent isn't compatible with Qt4 in this place.

I assume you're doing a custom build, since there are no official Qt builds for clang.

I use an official FreeBSD build of Qt port.

But I can easily patch this, I only reported here because I felt this place is better removed. It doesn't look like the right code anyway.

@yurivict commented on GitHub (Jan 8, 2016): The problem only occurs with Qt4. Qt5 doesn't have this problem. @glassez the #error Q_COMPILER_INITIALIZER_LISTS is undefined! does get triggered. It appears that qBittorrent isn't compatible with Qt4 in this place. > I assume you're doing a custom build, since there are no official Qt builds for clang. I use an official FreeBSD build of Qt port. But I can easily patch this, I only reported here because I felt this place is better removed. It doesn't look like the right code anyway.
Author
Owner

@Chocobo1 commented on GitHub (Jan 8, 2016):

You might want to remove the (possibly non-standard) constructor, and only delete based on the platform (with ifdefs). Or just list them all explicitly.

But I can easily patch this, I only reported here because I felt this place is better removed. It doesn't look like the right code anyway.

But it is valid C++11 code.

https://en.wikipedia.org/wiki/C%2B%2B11#Initializer_lists
http://blog.qt.io/blog/2011/05/26/cpp0x-in-qt/
http://doc.qt.io/qt-4.8/qstringlist.html#QStringList-5

@Chocobo1 commented on GitHub (Jan 8, 2016): > You might want to remove the (possibly non-standard) constructor, and only delete based on the platform (with ifdefs). Or just list them all explicitly. > > But I can easily patch this, I only reported here because I felt this place is better removed. It doesn't look like the right code anyway. But it is valid C++11 code. https://en.wikipedia.org/wiki/C%2B%2B11#Initializer_lists http://blog.qt.io/blog/2011/05/26/cpp0x-in-qt/ http://doc.qt.io/qt-4.8/qstringlist.html#QStringList-5
Author
Owner

@yurivict commented on GitHub (Jan 8, 2016):

The same compiler understands it for Qt5 but not for Qt4. It might be that DEFINES += Q_COMPILER_INITIALIZER_LISTS is required for Qt4, and is pre-defined for Qt5. I don't know where Q_COMPILER_INITIALIZER_LISTS is normally defined, but in both Qt4 and Qt5 such constructor is only available with Q_COMPILER_INITIALIZER_LISTS.

@yurivict commented on GitHub (Jan 8, 2016): The same compiler understands it for Qt5 but not for Qt4. It might be that DEFINES += Q_COMPILER_INITIALIZER_LISTS is required for Qt4, and is pre-defined for Qt5. I don't know where Q_COMPILER_INITIALIZER_LISTS is normally defined, but in both Qt4 and Qt5 such constructor is only available with Q_COMPILER_INITIALIZER_LISTS.
Author
Owner

@naikel commented on GitHub (Jan 8, 2016):

It is defined in qcompilerdetection.h but don't think Qt4 has Q_COMPILER_INITIALIZER_LISTS. You can check looking at the header of, for example, qstringlist.h (this issue was opened because of that). You should see something like this in Qt5:

#ifdef Q_COMPILER_INITIALIZER_LISTS
   inline QStringList(std::initializer_list<QString> args) : QList<QString>(args) { }
#endif

But I don't think you would see that in a qstringlist.h of Qt4.

Back to qcompilerdetection.h, to define Q_COMPILER_INITIALIZER_LISTS for clang, __cplusplus has to be >= 201103L and __has_feature(cxx_generalized_initializers) has to be true.

@naikel commented on GitHub (Jan 8, 2016): It is defined in qcompilerdetection.h but don't think Qt4 has Q_COMPILER_INITIALIZER_LISTS. You can check looking at the header of, for example, qstringlist.h (this issue was opened because of that). You should see something like this in Qt5: ``` #ifdef Q_COMPILER_INITIALIZER_LISTS inline QStringList(std::initializer_list<QString> args) : QList<QString>(args) { } #endif ``` But I don't think you would see that in a qstringlist.h of Qt4. Back to qcompilerdetection.h, to define Q_COMPILER_INITIALIZER_LISTS for clang, __cplusplus has to be >= 201103L and __has_feature(cxx_generalized_initializers) has to be true.
Author
Owner

@yurivict commented on GitHub (Jan 8, 2016):

I personally don't care, but it seems it is easiest to remove this code to make qbitorrent more compatible.

@yurivict commented on GitHub (Jan 8, 2016): I personally don't care, but it seems it is easiest to remove this code to make qbitorrent more compatible.
Author
Owner

@glassez commented on GitHub (Jan 8, 2016):

I personally don't care, but it seems it is easiest to remove this code to make qbitorrent more compatible.

qBittorrent uses c++11 now. All compilers and Qt versions supported by qBittorrent support c++11. We are not going to abandon this, if someone can't configure it.

@glassez commented on GitHub (Jan 8, 2016): > I personally don't care, but it seems it is easiest to remove this code to make qbitorrent more compatible. qBittorrent uses c++11 now. All compilers and Qt versions supported by qBittorrent support c++11. We are not going to abandon this, if someone can't configure it.
Author
Owner

@yurivict commented on GitHub (Jan 8, 2016):

Who can't configure it?

@yurivict commented on GitHub (Jan 8, 2016): Who can't configure it?
Author
Owner

@sledgehammer999 commented on GitHub (Jan 8, 2016):

@yurivict look at my comment here. The same file controls things for the other compilers too. Try to figure out why it doesn't enable that define for clang.

@sledgehammer999 commented on GitHub (Jan 8, 2016): @yurivict look at my comment [here](https://github.com/qbittorrent/qBittorrent/issues/4507#issuecomment-169828633). The same file controls things for the other compilers too. Try to figure out why it doesn't enable that define for clang.
Author
Owner

@yurivict commented on GitHub (Jan 8, 2016):

In Qt4 Q_COMPILER_INITIALIZER_LISTS is defined only when _LIBCPP_VER is defined, and _LIBCPP_VER isn't defined for me. So the constructor that you use isn't (always) defined by default in Qt4. Qt5 has different logic for Q_COMPILER_INITIALIZER_LISTS. I don't know if I should set _LIBCPP_VER. Why should I? What is it? Why isn't it set?

@yurivict commented on GitHub (Jan 8, 2016): In Qt4 Q_COMPILER_INITIALIZER_LISTS is defined only when _LIBCPP_VER is defined, and _LIBCPP_VER isn't defined for me. So the constructor that you use isn't (always) defined by default in Qt4. Qt5 has different logic for Q_COMPILER_INITIALIZER_LISTS. I don't know if I should set _LIBCPP_VER. Why should I? What is it? Why isn't it set?
Author
Owner

@yurivict commented on GitHub (Jan 8, 2016):

"Go to line 920 and uncomment it" doesn't work because this is the standard installation. Can't touch it. In short, qBittorrent isn't generally compatible with Qt4 out of the box due to this one line.

@yurivict commented on GitHub (Jan 8, 2016): "Go to line 920 and uncomment it" doesn't work because this is the standard installation. Can't touch it. In short, qBittorrent isn't generally compatible with Qt4 out of the box due to this one line.
Author
Owner

@sledgehammer999 commented on GitHub (Jan 8, 2016):

IIRC "clang" is among the unsupported or partially supported compilers by qt. Also qt4 isn't updated anymore and that's why it doesn't work. I think it is the job of the FreeBSD maintainer of qt4 to patch things up so they work(ie find what needs to be done to enable the Q_COMPILER_INITIALIZER_LISTS)

"Go to line 920 and uncomment it" doesn't work because this is the standard installation. Can't touch it. In short, qBittorrent isn't generally compatible with Qt4 out of the box due to this one line.

Sure but you could look at that file and see why it isn't enabled.

@sledgehammer999 commented on GitHub (Jan 8, 2016): IIRC "clang" is among the unsupported or partially supported compilers by qt. Also qt4 isn't updated anymore and that's why it doesn't work. I think it is the job of the FreeBSD maintainer of qt4 to patch things up so they work(ie find what needs to be done to enable the `Q_COMPILER_INITIALIZER_LISTS`) > "Go to line 920 and uncomment it" doesn't work because this is the standard installation. Can't touch it. In short, qBittorrent isn't generally compatible with Qt4 out of the box due to this one line. Sure but you could look at that file and see why it isn't enabled.
Author
Owner

@yurivict commented on GitHub (Jan 8, 2016):

Okay then, this is clang fault, it is unsupported, and nobody else uses it. So I close this then. I am not suffering from this. There are much more important issues.

@yurivict commented on GitHub (Jan 8, 2016): Okay then, this is clang fault, it is unsupported, and nobody else uses it. So I close this then. I am not suffering from this. There are much more important issues.
Author
Owner

@sledgehammer999 commented on GitHub (Jan 8, 2016):

Well it isn't clang's fault. It supports that feature. It is qt4's fault which is old and isn't configured correctly for clang. While qt5 is configured correctly which proves that clang works.

@sledgehammer999 commented on GitHub (Jan 8, 2016): Well it isn't clang's fault. It supports that feature. It is qt4's fault which is old and isn't configured correctly for clang. While qt5 is configured correctly which proves that clang works.
Author
Owner

@glassez commented on GitHub (Jan 8, 2016):

Qt4 supports c++11 features if used compiler supports it. There is simply no reliable way to determine the characteristics of future versions of the compilers. Or, maybe Qt4 just does it incorrectly. So there is nothing wrong to fix legacy configuration files.

@glassez commented on GitHub (Jan 8, 2016): Qt4 supports c++11 features if used compiler supports it. There is simply no reliable way to determine the characteristics of future versions of the compilers. Or, maybe Qt4 just does it incorrectly. So there is nothing wrong to fix legacy configuration files.
Author
Owner

@yurivict commented on GitHub (Jan 8, 2016):

Thanks to everybody for helping to clarify this issue.
It became 100% clear what is happening in this case.

@yurivict commented on GitHub (Jan 8, 2016): Thanks to everybody for helping to clarify this issue. It became 100% clear what is happening in this case.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/qBittorrent#3685
No description provided.