Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. '#pragma optimize' is not supported
Forum Updated to NodeBB v4.3 + New Features

'#pragma optimize' is not supported

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 4 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Spiel
    wrote on 16 Aug 2021, 05:54 last edited by
    #1

    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

    J 1 Reply Last reply 16 Aug 2021, 06:09
    0
    • S Spiel
      16 Aug 2021, 07:51

      @jsulm The message does not appear in compile output.

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 16 Aug 2021, 07:55 last edited by
      #9

      @Spiel Then all is fine and pragma works. QtCreator often shows false warnings.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • S Spiel
        16 Aug 2021, 05:54

        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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 16 Aug 2021, 06:09 last edited by
        #2

        @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?

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • S Offline
          S Offline
          Spiel
          wrote on 16 Aug 2021, 06:22 last edited by
          #3

          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.

          J 1 Reply Last reply 16 Aug 2021, 06:27
          0
          • S Spiel
            16 Aug 2021, 06:22

            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.

            J Offline
            J Offline
            JonB
            wrote on 16 Aug 2021, 06:27 last edited by JonB
            #4

            @Spiel
            It sounds like it ought to be OK. Why don't you start from a 10-line program, no classes etc., and see whether it ever works for you? Then build up from there.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Spiel
              wrote on 16 Aug 2021, 07:12 last edited by
              #5

              I did that, but the same message appears:
              58fb5c93-5559-4c02-990e-d11b9b5c10ac-image.png

              J J 2 Replies Last reply 16 Aug 2021, 07:27
              0
              • S Spiel
                16 Aug 2021, 07:12

                I did that, but the same message appears:
                58fb5c93-5559-4c02-990e-d11b9b5c10ac-image.png

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 16 Aug 2021, 07:27 last edited by
                #6

                @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?

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                S 1 Reply Last reply 16 Aug 2021, 07:51
                1
                • S Spiel
                  16 Aug 2021, 07:12

                  I did that, but the same message appears:
                  58fb5c93-5559-4c02-990e-d11b9b5c10ac-image.png

                  J Offline
                  J Offline
                  JonB
                  wrote on 16 Aug 2021, 07:31 last edited by
                  #7

                  @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 looks gcc-ish! So something to do with the Code Model Creator is using to examine your code, not the actual MSVC compiler?

                  1 Reply Last reply
                  0
                  • J jsulm
                    16 Aug 2021, 07:27

                    @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?

                    S Offline
                    S Offline
                    Spiel
                    wrote on 16 Aug 2021, 07:51 last edited by
                    #8

                    @jsulm The message does not appear in compile output.

                    J 1 Reply Last reply 16 Aug 2021, 07:55
                    0
                    • S Spiel
                      16 Aug 2021, 07:51

                      @jsulm The message does not appear in compile output.

                      J Offline
                      J Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 16 Aug 2021, 07:55 last edited by
                      #9

                      @Spiel Then all is fine and pragma works. QtCreator often shows false warnings.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on 16 Aug 2021, 08:35 last edited by Chris Kawa
                        #10

                        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.

                        1 Reply Last reply
                        3

                        3/10

                        16 Aug 2021, 06:22

                        7 unread
                        • Login

                        • Login or register to search.
                        3 out of 10
                        • First post
                          3/10
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • Users
                        • Groups
                        • Search
                        • Get Qt Extensions
                        • Unsolved