1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

Ticket #3786 (closed defect: fixed)

Opened 13 months ago

Last modified 9 months ago

Analysis failed (simplifyEnum)

Reported by: amaigil2 Owned by: danielmarjamaki
Priority: Normal Milestone:
Component: Other Keywords:
Cc: amaigil2

Description

The attached code returns Analysis failed. If the code is valid then please report this failure.

However it is valid code.

Attachments

analysis_failed_3786.cpp (0.5 KB) - added by amaigil2 13 months ago.
Example code
enum31.diff (2.4 KB) - added by iobyte 9 months ago.

Change History

Changed 13 months ago by amaigil2

Example code

follow-up: ↓ 2   Changed 13 months ago by danielmarjamaki

  • owner changed from noone to danielmarjamaki
  • status changed from new to accepted
  • milestone set to 1.55

thank you for reducing your code and reporting it. I'll try to fix it

in reply to: ↑ 1   Changed 12 months ago by amaigil2

Replying to danielmarjamaki:

thank you for reducing your code and reporting it. I'll try to fix it

BTW, I think that is a regression since short time. That code probably didn't change on my side, and cppcheck never worried about it.

  Changed 11 months ago by danielmarjamaki

  • milestone 1.55 deleted

This seems to be too complicated to fix now.

  Changed 10 months ago by danielmarjamaki

This seems to be too complicated to fix now.

I can fix it now.. but I fail to reproduce with latest git head.

  Changed 10 months ago by danielmarjamaki

  • status changed from accepted to closed
  • resolution set to fixed
  • milestone set to 1.56

I can reproduce with cppcheck-1.55. So I assume that this is fixed.

  Changed 10 months ago by amaigil2

I can confirm the fix!

  Changed 9 months ago by amaigil2

  • cc amaigil2 added
  • status changed from closed to reopened
  • resolution fixed deleted

Unfortunately today I see the same problem again :-(

  Changed 9 months ago by danielmarjamaki

I guess this is fixed by the new enum handling.

I reverted the new enum handling with:
0254344df53d543359d1dfac4f1c35a3070842a3

and then the "analysis failed" came back.

I intend to re-add the new enum handling later.

  Changed 9 months ago by iobyte

Please add the scope tracking code from simplifyTypedef before doing anything else to simplifyEnum. It should be pretty much cut and paste since simplifyEnum started out as a cut and pasted simplifyTypedef. Unfortunately simplifyEnum didn't get the scope tracking code when it was added to simplifyTypedef.

That should fix code like this:

struct Fred {
    enum { X = 5 };
    int foo();
};

int Fred::Foo() {
    return X;
}

from being tokenized like this:

1: struct Fred {
2:
3: int foo ( ) ;
4: } ;
5:
6: int Fred :: Foo ( ) {
7: return X ;
8: }

Class enum support is really broken now so that should be fixed first before any optimizations are added back that further diverge simplifyEnum from simplifyTypedef.

  Changed 9 months ago by iobyte

Here is a better scope test:

namespace N {
    class C {
    public:
        struct Fred {
            enum { X = 5 };
            int foo();
        };
    };
}

int N::C::Fred::foo() {
    return X;
}

  Changed 9 months ago by iobyte

Fixing the scope problem should also fix #4025 which should be reopened until a proper scope tracking fix is introduced.

  Changed 9 months ago by pkeus

#4025 is fixed and I think, it should remain closed.

  Changed 9 months ago by danielmarjamaki

  • summary changed from Analysis failed to Analysis failed (simplifyEnum)

Please add the scope tracking code from simplifyTypedef before doing anything else to simplifyEnum. It should be pretty much cut and paste since simplifyEnum started out as a cut and pasted simplifyTypedef.

sounds good. if you have the time.. it would be nice with a patch.

  Changed 9 months ago by iobyte

Here is a patch for the TODO test.

Changed 9 months ago by iobyte

  Changed 9 months ago by pkeus

  • milestone 1.56 deleted

  Changed 9 months ago by danielmarjamaki

I am not really sure this is a simplifyEnum bug after all.

I reduced your code to:

a<(b>c)> d;

That gives a "Analysis failed" message both with latest git head and 1.56.

  Changed 9 months ago by amai

  • status changed from reopened to closed
  • resolution set to fixed

Talking about the initial example, after PKEuS's https://github.com/danmar/cppcheck/commit/d44f10fc0147b8d7c6506ebe420e6d666c62ab47 the error is gone!

Note: See TracTickets for help on using tickets.