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. Why does this code get through the compiler without a return statement?
Forum Updated to NodeBB v4.3 + New Features

Why does this code get through the compiler without a return statement?

Scheduled Pinned Locked Moved General and Desktop
8 Posts 5 Posters 4.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.
  • J Offline
    J Offline
    Jonathan
    wrote on 21 Dec 2010, 15:21 last edited by
    #1

    This must be a real newbie question.

    I have this method declaration in the header (dbaccess.h):
    @static QStringList indexProperties();@

    and this definition in dbaccess.cpp:
    @QStringList DBAccess::indexProperties()
    {
    }@

    ie I've failed to provide return a value. I've just spent ages attempting to debug the problem, before spotting the obvious. Why doesn't the compiler pick up the missing return?

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on 21 Dec 2010, 15:43 last edited by
      #2

      With gcc you only get a warning:

      @
      dbaccess.cpp:91: warning: control reaches end of non-void function
      @

      Visual Studio emit something similar if I remember correctly.

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on 21 Dec 2010, 15:45 last edited by
        #3

        VS throws an error.
        @
        error C4716: 'AAA::BBB' : must return a value
        @
        Just live tested with VS2008 SP1

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • F Offline
          F Offline
          florent.revelut
          wrote on 21 Dec 2010, 15:55 last edited by
          #4

          Obviously depends on the compiler... With gcc, don't forget to set -Wall
          VS2008 does it out of the box

          1 Reply Last reply
          0
          • J Offline
            J Offline
            Jonathan
            wrote on 21 Dec 2010, 16:05 last edited by
            #5

            Yup, I'm using the MinGW tool chain under Windows 7.

            Live and learn.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              goetz
              wrote on 21 Dec 2010, 16:21 last edited by
              #6

              You can turn warnings into errors in gcc with -Werror switch. You can enable this by adding this to your .pro file:

              @
              QMAKE_CXXFLAGS += -Werror
              @

              http://www.catb.org/~esr/faqs/smart-questions.html

              1 Reply Last reply
              0
              • F Offline
                F Offline
                Franzk
                wrote on 22 Dec 2010, 08:02 last edited by
                #7

                [quote author="florent.revelut" date="1292946918"]VS2008 does it out of the box[/quote] Depends on your warning level just like with gcc, if I recall correctly.

                "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  giesbert
                  wrote on 22 Dec 2010, 08:14 last edited by
                  #8

                  [quote author="Franzk" date="1293004949"][quote author="florent.revelut" date="1292946918"]VS2008 does it out of the box[/quote] Depends on your warning level just like with gcc, if I recall correctly.

                  [/quote]

                  Hi,

                  In MSVS it's an error not a warning. I always use default levels: Warning level 3, no warning --> error translation. The MS compilers throw errors for such constructs.

                  Nokia Certified Qt Specialist.
                  Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                  1 Reply Last reply
                  0

                  1/8

                  21 Dec 2010, 15:21

                  • Login

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