[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [csmith-dev] csmith-dev Digest, Vol 44, Issue 2



Hello,

I had a look at the csmit code base some time ago.
In my humble opinion, there is some potential for using C++11 features to simplify (modernize) the code base, e.g,
in src/AbsExtension.cpp there is the following simple function.

void
AbsExtension::GenerateFirstParameterList(Function &curFunc, std::vector<ExtensionValue *> &values)
{
        vector<ExtensionValue *>::iterator i;
        for (i = values.begin(); i != values.end(); ++i) {
                assert(*i);
                CVQualifiers qfer = (*i)->get_qfer();
                Variable * v = VariableSelector::GenerateParameterVariable((*i)->get_type(), &qfer);
                assert(v);
                curFunc.param.push_back(v);
        }
}

One (!) simple use of C++11 would be to declare the iterator variable ‘i’ in the loop (in fact, that is already standard in C++03) 
and use ‘auto’ to let the compiler figure out its exact type.
The result would be as follows.

void
AbsExtension::GenerateFirstParameterList(Function &curFunc, std::vector<ExtensionValue *> &values)
{
        for (auto i = values.begin(); i != values.end(); ++i) { 
                assert(*i);
                CVQualifiers qfer = (*i)->get_qfer();
                Variable * v = VariableSelector::GenerateParameterVariable((*i)->get_type(), &qfer);
                assert(v);
                curFunc.param.push_back(v);
        }
}

Not a big deal, but there are many place likes this in Csmith.

Regards

Jens