Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 897513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:53:54+00:00 2026-05-15T14:53:54+00:00

Okay, little oddity I discovered with my C++ compiler. I had a not-overly complex

  • 0

Okay, little oddity I discovered with my C++ compiler.

I had a not-overly complex bit of code to refactor, and I accidentally managed to leave in a path that didn’t have a return statement. My bad. On the other hand, this compiled, and segfaulted when I ran it and that path was hit, obviously.

Here’s my question: Is this a compiler bug, or is there no guarantee that a C++ compiler will enforce the need for a return statement in a non-void return function?

Oh, and to be clear, in this case it was an unecessary if statement without an accompanying else. No gotos, no exits, no aborts.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T14:53:55+00:00Added an answer on May 15, 2026 at 2:53 pm

    Personally I think this should be an error:

    int f() {
    }
    
    int main() {
        int n = f();
        return 0;
    }
    

    but most compilers treat it as a warning, and you may even have to use compiler switches to get that warning. For example, on g++ you need -Wall to get:

    [neilb@GONERIL NeilB]$ g++ -Wall nr.cpp
    nr.cpp: In function 'int f()':
    nr.cpp:2: warning: no return statement in function returning non-void
    

    Of course, with g++ you should always compile with at least -Wall anyway.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay I have updated my code a little, but I am still not exactly
Okay, this is starting to drive me a little bit nuts. I've tried several
Okay i'm a little bit stuck on how to solve this problem. When a
okay, my problem is a little bit more difficult than the title would tell...
UPDATE: Solved, i'm an idiot, thank you everyone! Okay little bit weird.. I just
Okay, here's my problem. Please forgive me as it's a little bit complicated. I'm
Okay, the post title might be a little confusing. I have this code: class
Okay, I am a little confused because this code was working and for some
Okay so I'm trying to make a little gag program that will run away
Okay, it took me a little while to narrow down this problem, but it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.