'#pragma optimize' is not supported
-
Hi,
I am developing an application for which I need to disable compiler optimization at a certain place in code. I intended to use
#pragma optimize("", off)
and then place#pragma optimize("", on)
at the beginning and end of the code block. However, I get a'#pragma optimize' is not supported
warning.Can someone point me to at what I am doing wrong here? I am using MSVC2019 32-bit compiler.
Thanks
-
Hi,
I am developing an application for which I need to disable compiler optimization at a certain place in code. I intended to use
#pragma optimize("", off)
and then place#pragma optimize("", on)
at the beginning and end of the code block. However, I get a'#pragma optimize' is not supported
warning.Can someone point me to at what I am doing wrong here? I am using MSVC2019 32-bit compiler.
Thanks
@Spiel said in '#pragma optimize' is not supported:
at the beginning and end of the code block
According to https://docs.microsoft.com/en-us/cpp/preprocessor/optimize?view=msvc-160 this pragma must be outside of a function - is this the case in your code?
-
Thank you for the fast reply.
Yes, the statement is placed in the .cpp file just before and after the function definition. The function itself is a class member.
-
@Spiel
I was going to say, before @jsulm beat me to it. There is something strange here. Your screenshot shows-Wignored-pragma-optimized
. I don't think that is an MSVC message, I don't think it accepts-W<word>
options like this, it looksgcc
-ish! So something to do with the Code Model Creator is using to examine your code, not the actual MSVC compiler? -
@Spiel That message could be from the code model in QtCreator.
Do a rebuild and check the compiler output: do you see this message also in compiler output? -
Qt Creator uses Clang for code model, so it will show warnings for MSVC specific stuff sometimes.
You can safely disable this warning by going to Tools -> Options -> C++ -> Code Model. Click on the Diagnostic Configuration button and in the dialog that opens select "Build-system warnings". Click on Copy and give the new configuration some friendly name. Select that new configuration and in the Clang Warnings below add
-Wno-ignored-pragma-optimize
. This will disable this particular warning in the ui. Don't worry, it will not affect how the code is compiled or what warnings are issued by the compiler. You can add more exclusions here if you ever find other MSVC specific differences.