Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. gcc no "unreachable code" warning?
Forum Updated to NodeBB v4.3 + New Features

gcc no "unreachable code" warning?

Scheduled Pinned Locked Moved Solved C++ Gurus
3 Posts 2 Posters 1.1k 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.
  • JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by JonB
    #1
    int func()
    {
      return 1;
      // further statements
      // and perhaps a return 2;
    }
    

    gcc 9.3.0. I compile with -Wall. No warning after the first return, nor in the clang-chacking Qt Creator code editor.

    I expected it would warn. I have searched web and over many years it seems some older -Wunreachable-code or similar has been deprecated/removed. So there is nothing now for this? Or, is there some extra warning I should be passing? Were you peeps aware of this and quite happy compiling your code without a warning for such an obviously wrong case?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      See https://gcc.gnu.org/legacy-ml/gcc-help/2011-05/msg00360.html

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      JonBJ 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        See https://gcc.gnu.org/legacy-ml/gcc-help/2011-05/msg00360.html

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Christian-Ehrlicher
        Yes, but see the complainant in the first post at https://gcc.gnu.org/bugzilla/show_bug.cgi?id=46476. I feel his pain.

        I ran

        int func()
        {
          return 1;
          return 2;
        }
        

        through a variety of the compilers at that Compiler Explorer/godbolt. Not one of them warned. Is it that we cannot set/adjust any compilation warnings there? I know you won't agree, but it's just sad that none of them offer to warn on the above :) :(

        1 Reply Last reply
        0

        • Login

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