| Summary: | wrong behaviour of "reformat source" (C++) | ||
|---|---|---|---|
| Product: | [Applications] kdevelop | Reporter: | elvio.amparore |
| Component: | Astyle | Assignee: | kdevelop-bugs-null |
| Status: | RESOLVED FIXED | ||
| Severity: | normal | CC: | prigault |
| Priority: | NOR | ||
| Version First Reported In: | 3.0.0b1 | ||
| Target Milestone: | --- | ||
| Platform: | RedHat Enterprise Linux | ||
| OS: | Linux | ||
| Latest Commit: | Version Fixed/Implemented In: | ||
| Sentry Crash Report: | |||
Confirmed on Kdevelop-3.1.2 (KDE-3.3.2) Can't reproduce with kdevelop-3.1.1 from yoper. CORRECTION:
> Confirmed on Kdevelop-3.1.2 (KDE-3.3.2)
This is on KDE-3.3.2 compiled from sources (gcc-3.3.3) on Fedora Core 1.
When I use the same sources (kdevelop-3.1.2 on KDE-3.3.2) compiled (gcc-3.4.2) on Fedora Core 3, the bug does *not* happen (i.e formatting works OK).
So what you are saying is that astyle has a bug with gcc < 3.4.2 ? > So what you are saying is that astyle has a bug with gcc < 3.4.2 ?
From the symptoms, it looks like it, but I looked into this further and did not reach conclusive evidence yet.
I downloaded astyle_1.15.3 from sourceforge and tested it on:
A) Fedora Core 1 box (i686) with gcc-3.3.3
B) Fedora Core 3 box (i686) with gcc-3.4.2
A) astyle compiles fine. Consistently shows the bug
1. astyle --style=gnu testcase.cc (same with --style=kr and --style=ansi)
if (pt.y>
=minY && pt.y<=maxY && pt.x>=minX && pt.x<=maxX)
2. astyle --style=linux testcase.cc
if (pt.y>
=minY && pt.y<=maxY && pt.x>=minX && pt.x<=maxX)
B) astyle does not compile with gcc-3.4.2 (which is correct behaviour, because astyle_main.cpp should not compile):
$ make
g++ -Wall -Wno-sign-compare -O2 -c ASResource.cpp
g++ -Wall -Wno-sign-compare -O2 -c ASBeautifier.cpp
g++ -Wall -Wno-sign-compare -O2 -c ASFormatter.cpp
g++ -Wall -Wno-sign-compare -O2 -c astyle_main.cpp
astyle_main.cpp: In function `bool parseOptions(astyle::ASFormatter&, const ITER&, const ITER&, const std::string&)':
astyle_main.cpp:178: error: there are no arguments to `parseOption' that depend on a template parameter, so a declaration of `parseOption' must be available
astyle_main.cpp:178: error: (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
astyle_main.cpp:183: error: there are no arguments to `parseOption' that depend on a template parameter, so a declaration of `parseOption' must be available
astyle_main.cpp:188: error: there are no arguments to `parseOption' that depend on a template parameter, so a declaration of `parseOption' must be available
make: *** [astyle_main.o] Error 1
Declaring properly the function (i.e inserting the following line before line 154 in astyle_main.cpp) is necessary to get astyle to compile.
bool parseOption(ASFormatter &formatter, const string &arg, const string &errorInfo);
Then, I gave it the testcase, and it showed the exact same behaviour as on A.
Then I realized that:
- the astyle classes distributed in kdevelop differ from those of astyle_1.15.3 (which version are they by the way?). Replace the classes ASBeautifier.cpp, ASFormatter.cpp and ASResource.cpp. Same result, bug shows up in command-line astyle on gcc-3.4.2.
- kdevelop has its own wrapper instead of astyle_main.cpp
So there is more work ahead to explain why I am seeing it with gcc-3.3.3 and not with gcc-3.4.2. By the way, I have two build of FC3/gcc-3.4.2: one on i386 and one on x86_64, and the bug happens on neihter of them.
Fixed in the KDevelop 3.4 branch as part of this commit: SVN commit 595657 by dymo: Applied patch from Megan Webb: Update to the astyle plugin to use astyle v1.19 Changes: - layout of the formatting dialog has changed to mirror the astyle command line options help. - all options from commandline astyle can be set. - interactive display of most options selected. - tooltips for all options |
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; }