Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

This resource has not currently been approved, and is not currently linked to from our directory of resources. It is being displayed here for preview by the author and moderators only.
Rated
Read 275 times

Contents

Related Categories

The use of the code analysis library OpenC++: modifications, improvements, error corrections - 12. Support of definitions in classes of T (min)() { } type functions.

AndreyKarpov

12. Support of definitions in classes of T (min)() { } type functions.

Sometimes while programming one has to use workarounds to reach the desirable result. For example, a widely known macro "max" often causes troubles while defining in a class a method of "T max() {return m;}" type. In this case one resorts to some tricks and define the method as "T (max)() {return m;}". Unfortunately, OpenC++ doesn't understand such definitions inside classes. To correct this defect Parser::isConstructorDecl() function should be changed in the following way:

bool Parser::isConstructorDecl()
{
    if(lex->LookAhead(0) != '(')
        return false;
    else{
        // Support: T (min)() { }
        if (lex->LookAhead(1) == Identifier &&
            lex->LookAhead(2) == ')' &&
            lex->LookAhead(3) == '(')
          return false;
        ptrdiff_t t = lex->LookAhead(1);
        if(t == '*' || t == '&' || t == '(')
            return false;       // declarator
        else if(t == CONST || t == VOLATILE)
            return true;        // constructor or declarator
        else if(isPtrToMember(1))
            return false;       // declarator (::*)
        else
            return true;        // maybe constructor
    }
}

Comments