[Bug 68810] New: wrong behaviour of "reformat source" (C++)

elvio.amparore at libero.it elvio.amparore at libero.it
Sat Nov 22 21:33:06 UTC 2003


------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
     
http://bugs.kde.org/show_bug.cgi?id=68810     
           Summary: wrong behaviour of "reformat source" (C++)
           Product: kdevelop
           Version: unspecified
          Platform: RedHat RPMs
        OS/Version: Linux
            Status: UNCONFIRMED
          Severity: normal
          Priority: NOR
         Component: general
        AssignedTo: kdevelop-devel at kdevelop.org
        ReportedBy: elvio.amparore at libero.it


Version:           kdevelop3.0.0b1 (using KDE KDE 3.1)
Installed from:    RedHat RPMs
Compiler:          gcc 3.2.2 
OS:          Linux

the menu function "reformat source" change a line of the following code from:
        if (pt.y>=minY && pt.y<=maxY && pt.x>=minX && pt.x<=maxX)
            return true;
to:
        if (pt.y>
                =minY && pt.y<=maxY && pt.x>=minX && pt.x<=maxX)
            return true;

which is incorrect. I think that the problem is related to templates (and angle brackets), but see the code, that should compile.
Feel free to e-mail me for questions.




#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <iostream>
#include <cstdlib>

using namespace std;

// this is a modified Simple Hello World application (C++).
/* The bug happens when i try to use "reformat source" to the entire file,
 * because kdevelop corrupts a symbol (a <=) in Function().
 *
 * I suspect that the bug is related to static members inside templates.
 */

// some macros/defs to compile the code
#define DLLAPI
#define ABS(x) ((x)<0 ? -(x) : (x))

template <class type_t>
class Math
{
public:
    static const type_t EPSILON;
};

template <>
class Math<double>
{
public:
    static const double EPSILON;
};

// this is part of the implementation:
template<>
const double Math<double>::EPSILON  = 0.00001;

// a simple Vector2
typedef double real_t;
struct Vector2
{
    real_t x, y;
};

// here is the function
bool DLLAPI Function (const Vector2& vA, const Vector2& vB,
                      const Vector2& pt, real_t tolerance)
{
    real_t DeltaX =vB.x - vA.x, AbsDeltaX =ABS (DeltaX);
    real_t DeltaY =vB.y - vA.y, AbsDeltaY =ABS (DeltaY);
    real_t minX = min (vB.x, vA.x) - tolerance;
    real_t maxX = max (vB.x, vA.x) + tolerance;
    real_t minY = min (vB.y, vA.y) - tolerance;
    real_t maxY = max (vB.y, vA.y) + tolerance;
    real_t a, b, c, nX, nY;

    if (AbsDeltaX<=Math<real_t>::EPSILON && AbsDeltaY<=Math<real_t>::EPSILON)
    {
        // the bug happens here: 'pt.y>' 'newline' '=minY'
        // '>=' is broken when the source is reformatted
        if (pt.y>=minY && pt.y<=maxY && pt.x>=minX && pt.x<=maxX)
            return true;
        else
            return false;
    }
    // other code ...

    // NOTE that the same code is not affected by any bug if I don't use Math<real_t>::EPSILON
    if (AbsDeltaX<=/*Math<real_t>::EPSILON*/0.001 && AbsDeltaY<=/*Math<real_t>::EPSILON*/0.001)
    {
        if (pt.y>=minY && pt.y<=maxY && pt.x>=minX && pt.x<=maxX)
            return true;
        else
            return false;
    }
    // the same line, without bug
    if (pt.y>=minY && pt.y<=maxY && pt.x>=minX && pt.x<=maxX)
        return true;
    else
        return false;

    // ...
}




int main( int argc, char *argv[] )
{
    cout << "Hello, world!" << endl;
    return EXIT_SUCCESS;
}




More information about the KDevelop-devel mailing list