Discussion:
[Qt-creator] Clang code model running in C++98 mode
Julius Bullinger
2018-11-06 10:41:41 UTC
Permalink
Hi,

we have a medium-sized qmake project (about 300 .pri/.pro files), which
all contain "CONFIG += c++11". However, the clang code model doesn't
seem to catch that, and runs in C++98 mode regardless:

CTRL+Shift+F12 > Projects Parts > General > Language Version: CXX98

This causes hundreds of errors and warnings in the editor about C++11
extensions and unknown types. With the traditional code model, the
project is detected as C++11/14 correctlty.

I can't reproduce it with a smaller project, but is there any way I can
debug this issue? Like get the options that are passed from qmake to the
code model?

Thanks and best regards,
Julius
Nikolai Kosjar
2018-11-06 11:19:28 UTC
Permalink
On 11/6/18 11:41 AM, Julius Bullinger wrote:
> Hi,
>
> we have a medium-sized qmake project (about 300 .pri/.pro files), which
> all contain "CONFIG += c++11". However, the clang code model doesn't
> seem to catch that, and runs in C++98 mode regardless:
>
> CTRL+Shift+F12 > Projects Parts > General > Language Version: CXX98
>
> This causes hundreds of errors and warnings in the editor about C++11
> extensions and unknown types. With the traditional code model, the
> project is detected as C++11/14 correctlty.

Recently there were some changes in that area. Could you please try
again with the updated snapshots for 4.8?

http://download.qt.io/snapshots/qtcreator/4.8/4.8.0-beta2

> I can't reproduce it with a smaller project, but is there any way I can
> debug this issue? Like get the options that are passed from qmake to the
> code model?

A breakpoint in ProjectInfoGenerator::createProjectPart() should help,
especially on

part->languageVersion = macroInspectionReport.languageVersion;

Nikolai
Julius Bullinger
2018-11-06 12:51:40 UTC
Permalink
On 06.11.2018 12:19, Nikolai Kosjar wrote:
> On 11/6/18 11:41 AM, Julius Bullinger wrote:
>> Hi,
>>
>> we have a medium-sized qmake project (about 300 .pri/.pro files), which
>> all contain "CONFIG += c++11". However, the clang code model doesn't
>> seem to catch that, and runs in C++98 mode regardless:
>>
>> CTRL+Shift+F12 > Projects Parts > General > Language Version: CXX98
>>
>> This causes hundreds of errors and warnings in the editor about C++11
>> extensions and unknown types. With the traditional code model, the
>> project is detected as C++11/14 correctlty.
>
> Recently there were some changes in that area. Could you please try
> again with the updated snapshots for 4.8?

I forgot to mention that, it also happens with the latest 4.8 snapshot
(2581).

>> I can't reproduce it with a smaller project, but is there any way I can
>> debug this issue? Like get the options that are passed from qmake to the
>> code model?
>
> A breakpoint in ProjectInfoGenerator::createProjectPart() should help,
> especially on
>
> part->languageVersion = macroInspectionReport.languageVersion;

Well, I'd need to built Creator myself for that. I'll have to see if
that's feasible. Thanks for the pointer, though!

Regards,
Julius
Julius Bullinger
2018-11-15 14:55:23 UTC
Permalink
Hi Nikolai

On 06.11.2018 12:19, Nikolai Kosjar wrote:
> Recently there were some changes in that area. Could you please try
> again with the updated snapshots for 4.8?
>
> http://download.qt.io/snapshots/qtcreator/4.8/4.8.0-beta2

I managed to built the latest 4.8 branch on my machine, and still got
the same issue:

>> I can't reproduce it with a smaller project, but is there any way I can
>> debug this issue? Like get the options that are passed from qmake to the
>> code model?
>
> A breakpoint in ProjectInfoGenerator::createProjectPart() should help,
> especially on
>
> part->languageVersion = macroInspectionReport.languageVersion;
>

On the first break after loading the project,
macroInspectionReport.languageVersion is CXX14 (7). On further breaks,
it's CXX98 (4).

I cannot find any differences in the respective qmake projects. The
flags.commandLineFlags that are passed are the following:

-nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline /wd4503 /w14239 /FC
/D_LIntStatic /Zi /Fd<path> -O2 -Zi -MD -Zc:strictStrings -W3 -w34100
-w34189 -w44996 /WX -EHsc

However, I found that in tcInfo.macroInspectionRunner, the "__cplusplus"
macro has a value of 199711L. This is from msvctoolchain.cpp, which
shows some information about the possible values:

// We want to detect the language version based on the predefined macros.
// Unfortunately MSVC does not conform to standard when it comes to the
predefined
// __cplusplus macro - it reports "199711L", even for newer language
versions.
//
// However:
// * For >= Visual Studio 2015 Update 3 predefines _MSVC_LANG which
has the proper value
// of __cplusplus.
// See
https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2017
// * For >= Visual Studio 2017 Version 15.7 __cplusplus is correct
once /Zc:__cplusplus
// is provided on the command line. Then __cplusplus == _MSVC_LANG.
// See
https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus
//
// We rely on _MSVC_LANG if possible, otherwise on some hard coded
language versions
// depending on _MSC_VER.

We're still running MSVC 2013, which doesn't seem to be covered by this
exceptions. I tested opening the project with a MSVC 2017 Version 15.8
kit, and with that, the code model reports a C++ version of CXX17
(although it should be C++11)!

So, I guess this is a bug in Creator regarding C++ version detection
with MSVC 2013?

If so, I'll file a bug report.

Thanks,
Julius
Nikolai Kosjar
2018-11-15 15:33:50 UTC
Permalink
On 11/15/18 3:55 PM, Julius Bullinger wrote:
> Hi Nikolai
>
> On 06.11.2018 12:19, Nikolai Kosjar wrote:
>> Recently there were some changes in that area. Could you please try
>> again with the updated snapshots for 4.8?
>>
>> http://download.qt.io/snapshots/qtcreator/4.8/4.8.0-beta2
>
> I managed to built the latest 4.8 branch on my machine, and still got
> the same issue:
>
>>> I can't reproduce it with a smaller project, but is there any way I can
>>> debug this issue? Like get the options that are passed from qmake to the
>>> code model?
>>
>> A breakpoint in ProjectInfoGenerator::createProjectPart() should help,
>> especially on
>>
>>     part->languageVersion = macroInspectionReport.languageVersion;
>>
>
> On the first break after loading the project,
> macroInspectionReport.languageVersion is CXX14 (7). On further breaks,
> it's CXX98 (4).
>
> I cannot find any differences in the respective qmake projects. The
> flags.commandLineFlags that are passed are the following:
>
> -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline /wd4503 /w14239 /FC
> /D_LIntStatic /Zi /Fd<path> -O2 -Zi -MD -Zc:strictStrings -W3 -w34100
> -w34189 -w44996 /WX -EHsc
>
> However, I found that in tcInfo.macroInspectionRunner, the "__cplusplus"
> macro has a value of 199711L. This is from msvctoolchain.cpp, which
> shows some information about the possible values:
>
> // We want to detect the language version based on the predefined macros.
> // Unfortunately MSVC does not conform to standard when it comes to the
> predefined
> // __cplusplus macro - it reports "199711L", even for newer language
> versions.
> //
> // However:
> //   * For >= Visual Studio 2015 Update 3 predefines _MSVC_LANG which
> has the proper value
> //     of __cplusplus.
> //     See
> https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2017
>
> //   * For >= Visual Studio 2017 Version 15.7 __cplusplus is correct
> once /Zc:__cplusplus
> //     is provided on the command line. Then __cplusplus == _MSVC_LANG.
> //     See
> https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus
>
> //
> // We rely on _MSVC_LANG if possible, otherwise on some hard coded
> language versions
> // depending on _MSC_VER.
>
> We're still running MSVC 2013, which doesn't seem to be covered by this
> exceptions. I tested opening the project with a MSVC 2017 Version 15.8
> kit, and with that, the code model reports a C++ version of CXX17
> (although it should be C++11)!
>
> So, I guess this is a bug in Creator regarding C++ version detection
> with MSVC 2013?

Looks like that, yes, please report.

For some reason the code path that checks _MSC_VER fails or is never
executed. Or there is a bug in the macro cache.

Nikolai
Marco Bubke
2018-11-15 15:42:00 UTC
Permalink
Hi


You cannot set MSVC 2017 Version 15.8 to C++11, only C++14 or C++17 is possible. If you set it to C++11 you should get C++17.

________________________________
From: Qt-creator <qt-creator-bounces+marco.bubke=***@qt-project.org> on behalf of Nikolai Kosjar <***@qt.io>
Sent: Thursday, November 15, 2018 4:33:50 PM
To: Julius Bullinger; qt-***@qt-project.org
Subject: Re: [Qt-creator] Clang code model running in C++98 mode

On 11/15/18 3:55 PM, Julius Bullinger wrote:
> Hi Nikolai
>
> On 06.11.2018 12:19, Nikolai Kosjar wrote:
>> Recently there were some changes in that area. Could you please try
>> again with the updated snapshots for 4.8?
>>
>> http://download.qt.io/snapshots/qtcreator/4.8/4.8.0-beta2
>
> I managed to built the latest 4.8 branch on my machine, and still got
> the same issue:
>
>>> I can't reproduce it with a smaller project, but is there any way I can
>>> debug this issue? Like get the options that are passed from qmake to the
>>> code model?
>>
>> A breakpoint in ProjectInfoGenerator::createProjectPart() should help,
>> especially on
>>
>> part->languageVersion = macroInspectionReport.languageVersion;
>>
>
> On the first break after loading the project,
> macroInspectionReport.languageVersion is CXX14 (7). On further breaks,
> it's CXX98 (4).
>
> I cannot find any differences in the respective qmake projects. The
> flags.commandLineFlags that are passed are the following:
>
> -nologo -Zc:wchar_t -FS -Zc:rvalueCast -Zc:inline /wd4503 /w14239 /FC
> /D_LIntStatic /Zi /Fd<path> -O2 -Zi -MD -Zc:strictStrings -W3 -w34100
> -w34189 -w44996 /WX -EHsc
>
> However, I found that in tcInfo.macroInspectionRunner, the "__cplusplus"
> macro has a value of 199711L. This is from msvctoolchain.cpp, which
> shows some information about the possible values:
>
> // We want to detect the language version based on the predefined macros.
> // Unfortunately MSVC does not conform to standard when it comes to the
> predefined
> // __cplusplus macro - it reports "199711L", even for newer language
> versions.
> //
> // However:
> // * For >= Visual Studio 2015 Update 3 predefines _MSVC_LANG which
> has the proper value
> // of __cplusplus.
> // See
> https://docs.microsoft.com/en-us/cpp/preprocessor/predefined-macros?view=vs-2017
>
> // * For >= Visual Studio 2017 Version 15.7 __cplusplus is correct
> once /Zc:__cplusplus
> // is provided on the command line. Then __cplusplus == _MSVC_LANG.
> // See
> https://blogs.msdn.microsoft.com/vcblog/2018/04/09/msvc-now-correctly-reports-__cplusplus
>
> //
> // We rely on _MSVC_LANG if possible, otherwise on some hard coded
> language versions
> // depending on _MSC_VER.
>
> We're still running MSVC 2013, which doesn't seem to be covered by this
> exceptions. I tested opening the project with a MSVC 2017 Version 15.8
> kit, and with that, the code model reports a C++ version of CXX17
> (although it should be C++11)!
>
> So, I guess this is a bug in Creator regarding C++ version detection
> with MSVC 2013?

Looks like that, yes, please report.

For some reason the code path that checks _MSC_VER fails or is never
executed. Or there is a bug in the macro cache.

Nikolai
Loading...