473,382 Members | 1,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Compiler bug: Not All code paths return a value

I was compiling the function below and received this error. Putting a return
statement after the loop solves the problem I believe this is a compiler
bug, as this code will always leave the function within the loop.

protected DateTime GetDate()
{
for (int i = 0; i < 3; i++)
{
try
{
return DateTime.Now;
}
catch
{
throw;
}
}
}

Niall
Nov 15 '05 #1
2 1238
This is not a bug - although for() is a well-known construct it still
requires run-time evaluation to test the entry to the loop. On the other
hand this:

static double GetValue()
{
for(;true;)
{
return 10d;
}
}

is compile-time deterministic and does compile.
Richard

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Niall" <as**@me.com> wrote in message
news:ej**************@TK2MSFTNGP12.phx.gbl...
I was compiling the function below and received this error. Putting a return statement after the loop solves the problem I believe this is a compiler
bug, as this code will always leave the function within the loop.

protected DateTime GetDate()
{
for (int i = 0; i < 3; i++)
{
try
{
return DateTime.Now;
}
catch
{
throw;
}
}
}

Niall

Nov 15 '05 #2
Ah, of course. I was not considering the case (for the compiler) where the
loop is not entered, I was thinking the compiler thought it could exit the
loop.

So this post ends up in the same basket as so many other bug reports -
Denied :P

Niall

"Richard A. Lowe" <ch*****@yumspamyumYahoo.com> wrote in message
news:uC**************@tk2msftngp13.phx.gbl...
This is not a bug - although for() is a well-known construct it still
requires run-time evaluation to test the entry to the loop. On the other
hand this:

static double GetValue()
{
for(;true;)
{
return 10d;
}
}

is compile-time deterministic and does compile.
Richard

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Niall" <as**@me.com> wrote in message
news:ej**************@TK2MSFTNGP12.phx.gbl...
I was compiling the function below and received this error. Putting a

return
statement after the loop solves the problem I believe this is a compiler
bug, as this code will always leave the function within the loop.

protected DateTime GetDate()
{
for (int i = 0; i < 3; i++)
{
try
{
return DateTime.Now;
}
catch
{
throw;
}
}
}

Niall


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
3
by: Alf P. Steinbach | last post by:
Code as follows: #include <iostream> // std::cout #include <string> // std::string #include <memory> // std::auto_ptr class Window { public: typedef...
13
by: Generic Usenet Account | last post by:
Compile the following snippet of code and run it. If the program spits out bat:bat instead of bat:zat, what would you say? Would you say that the compiler has a problem, or would you lay the...
5
by: Dylan | last post by:
Just wondered what you guys do when you need a method that returns a const reference to some data based upon some value. something like this: const CData& MyClass::GetDataWithValue(int...
43
by: Anitha | last post by:
Hi I observed something while coding the other day: if I declare a character array as char s, and try to use it as any other character array..it works perfectly fine most of the times. It...
2
by: Jan Bares | last post by:
Hi, I have found a bug in generated code in debug build. I have Visual C++ .NET 7.1.3088. Function Buggy::isBug() returns true and it should return false. The sample is contrived to exhibit the...
0
by: erik.erikson | last post by:
I am getting a compiler error that I can't well explain or even understand the origin of (though I boiled it down close...). Below is a bare-bones example. What I am doing is defining the...
49
by: valentin tihomirov | last post by:
fDeleted = false; uint jobId; foreach (Struct struct in structures) { if (struct.type == JOB) { jobId = struct.id; if (struct.dataType == STATUS) fDeteted = (struct.data & STATUS_DELETED) !=...
20
by: tshad | last post by:
I had posted this problem earlier and just noticed that the Hyperlink is the problem. Apparently, it doesn't figure out the path correctly. It uses the path of the file it is in, even if it is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.