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.0k 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 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

    jsulmJ 1 Reply Last reply
    0
    • S Spiel

      @jsulm The message does not appear in compile output.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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

        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

        jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on 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 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.

          JonBJ 1 Reply Last reply
          0
          • S Spiel

            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.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on 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 last edited by
              #5

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

              jsulmJ JonBJ 2 Replies Last reply
              0
              • S Spiel

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

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on 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
                1
                • S Spiel

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

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on 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
                  • jsulmJ jsulm

                    @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 last edited by
                    #8

                    @jsulm The message does not appear in compile output.

                    jsulmJ 1 Reply Last reply
                    0
                    • S Spiel

                      @jsulm The message does not appear in compile output.

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on 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
                      • Chris KawaC Offline
                        Chris KawaC Offline
                        Chris Kawa
                        Lifetime Qt Champion
                        wrote on 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

                        • Login

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