sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
Clemens Hintze's Avatar

Usage of default constructed slice allowed in valarray? [long]


Question posted by: Clemens Hintze (Guest) on November 7th, 2005 01:05 PM
Hello,

I have a question concerning the usage of default constructed
std::slice instances.

Our company currently validate the GNU-G++ 3.4 compiler against the
ISO/IEC 14882:2003 standard for compliance. We are using a commercial
testsuite that is sold explicitely for such validation purposes.

Now there occurs a problem, where the corresponding test produces a
core dump therefore rendering the test as failure.

Reading the standard, I am thinking the test implementation is okay.
But our G++ supplier do not agree with me. We both are digging in the
standard and cannot agree on its meaning for that purpose. So I would
like to ask for other opinions as well.

So here we go ...

----------------------8X-------------------------
#include <valarray>

int main() {
const std::valarray<int> va(3);
//std::slice sl; // (1) Uncomment this procduces core dump
//std::slice sl(0,0,0); // (2) Uncomments this, all wents well

std::valarray<int> va2 = va[sl];
}
----------------------8X-------------------------

In the testsuite the code is with like this with line (1) uncommented.
The test execution dumps core. However if I did uncomment (2) instead,
the program will runs fine without dumping core.

My question is now, if it is forbidden - following the standard- that
I use a default constructed slice [like in (1)] to select elements
within an valarray?

In Sec 26.3.4.1;1 there is written

"The default constructor for slice creates a slice which specifies no
elements. A default constructor is provided only to permit the
declaration of arrays of slices. The constructor with arguments for
a slice takes a start, length, and stride parameter."

I interpret this sentence so, that a default constructed slice specify
no elements like this regular constructed one:

std::slice sl(0,0,0);

I do not interpret the sentence concerning "(...) provided only (...)"
above the way, that any other usage of a default constructed slice
(besides declaring arrays of slices) would be forbidden and therefore
undefined.

Do anybody know better, how the Standard has meant usage of default
constructed slices? Result such usage in undefined behavior and
therefore I should expect a possible core dump?

If so, then I would have to bother our supplier of the compliance
testsuite to fix theirs tests, as they wouldn't be standard compliant
any more ... but before I bother them, I would like to hear some more
opinions!

Thanks in advance.

Best regards,
Clemens.
0 Answers Posted
 
Not the answer you were looking for? Post your question . . .
196,789 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,789 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors