views:

68

answers:

2

Having code:

Date::Date(const char* day, const char* month, const char* year):is_leap__(false)
{
    my_day_ = lexical_cast<int>(day);


    my_month_ = static_cast<Month>(lexical_cast<int>(month));

    /*Have to check month here, other ctor assumes month is correct*/
    if (my_month_ < 1 || my_month_ > 12)
    {
        throw std::exception("Incorrect month.");
    }
    my_year_ = lexical_cast<int>(year);

    if (!check_range_year_(my_year_))
    {
        throw std::exception("Year out of range.");
    }

    if (check_leap_year_(my_year_))//SKIPS THIS LINE
    {
        is_leap__ = true;
    }
    if (!check_range_day_(my_day_, my_month_))
    {
        throw std::exception("Day out of range.");
    }

}

bool Date::check_leap_year_(int year)const//IF I MARK THIS LINE WITH BREAKPOINT I'M GETTING MSG THAT THERE IS NO EXECUTABLE CODE IS ASSOSIATED WITH THIS LINE
{
    if (!(year%400) || (year%100 && !(year%4)))
    {
        return true;
    }
    else
    {
        return false;
    }
}

Which is very strange in my opinion. There is call to this fnc in my code, why compiler ignores that.
P.S. I'm trying to debug in release.

A: 

A function header does indeed not compile to any executable code. Try setting the breakpoint on the open brace, or the first statement in the function.

Thomas
That wouldn't do anything, VS would move it to the correct line.
GMan
+1  A: 

Trying to debug in release leads to pain. The function is being inlined, so you can't break on it. This kind of optimization will happen everywhere, values in variables will seem off, etc. Best to debug in debug.

By the way, just do: return !(year%400) || (year%100 && !(year%4));


What I mean by "it got inlined" is that your code, at that part, became:

if (!(my_year_%400) || (my_year_%100 && !(my_year_%4)))
{
    is_leap__ = true;
}

There is no function call, and nothing to break on.

GMan
@atch: @GMan is definitely right. Once a function gets inlined, the debugger won't even recognize the function's symbol as a valid symbol. Why would you want to debug in release mode anyway? Try debugging in debug mode, and if you're using GCC, compile with the `-g` flag and preferably leave out any `-Ox` flag (ie, leave out optimization). That should give you everything you need to have GDB debug the app correctly.
themoondothshine