andreasfertig / cppinsights

C++ Insights - See your source code with the eyes of a compiler
https://cppinsights.io
MIT License
4.05k stars 239 forks source link

Superfluous parentheses in declarations are handled incorrectly #606

Closed DivineWinds closed 7 months ago

DivineWinds commented 7 months ago

Input:

void (*p);

Output:

void (*) p;

This is wrong and fails to compile. Ideally the unnecessary parentheses would be removed but leaving them untouched is also an option.

andreasfertig commented 7 months ago

Hello @DivineWinds,

thanks for spotting this! A fix is on its way.

Andreas

DivineWinds commented 7 months ago

Thanks for the fix @andreasfertig. I'm sorry for being a nuisance but unfortunately I discovered a problem with it. void (**p); and deeper multilevel pointers still exhibit the old behaviour. Also, using cv-qualifiers breaks even the one level pointer case, that is, void (*volatile p); becomes void (*pvolatile); (I'm only using volatile to skip the initalizer. const does the same thing). Combining the two results in the old behaviour as well: void (**volatile p); becomes void (**volatile) p;.

EDIT: I don't know if this is useful in any way but turning any of the above examples into array declarations seems to fix them, e.g. void (**volatile p[2]); remains unchanged. There are however pathological array declarations like void (*(*p)[3]); -> void (*p(*)[3]);. The last thing I noticed is that adding typedef to any of the examples, including the last one makes them behave correctly.

andreasfertig commented 7 months ago

Hello @DivineWinds,

thanks for the testing. What is the use-case for all that? Is this production code?

Andreas

DivineWinds commented 7 months ago

I'm not aware of any use case. I originally found this by just copying the Most Vexing Parse example from Wikipedia and changing the type of my_dbl to double*. There was no reason for me to do this other than to see what would happen. After you fixed that, I tried some more complicated cases just to see how robust the fix was. So, as far as I know, you can ignore this issue and no production code would be affected.

Στις Τρί 13 Φεβ 2024, 16:22 ο χρήστης Andreas Fertig < @.***> έγραψε:

Hello @DivineWinds https://github.com/DivineWinds,

thanks for the testing. What is the use-case for all that? Is this production code?

Andreas

— Reply to this email directly, view it on GitHub https://github.com/andreasfertig/cppinsights/issues/606#issuecomment-1941625985, or unsubscribe https://github.com/notifications/unsubscribe-auth/A2NIDFGBEIGH5RVTTQHVICDYTNZJJAVCNFSM6AAAAABCLF4QGGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNBRGYZDKOJYGU . You are receiving this because you were mentioned.Message ID: @.***>