paul-j-lucas / cdecl

Composing and deciphering C (or C++) declarations or casts, aka ‘‘gibberish.’’
GNU General Public License v3.0
90 stars 11 forks source link

Invalid function declarator accepted as valid #32

Closed mzoz closed 10 months ago

mzoz commented 11 months ago

For example int foo()()() is comprehended as "declare foo as function returning function returning function returning int", but it's an invalid declarator and won't pass compilation, please help thanks!

paul-j-lucas commented 11 months ago

When I do it, I get:

declare foo as function returning integer

(which is also wrong).

mzoz commented 11 months ago

No worries Paul, it's indeed syntactically correct, but violates some misc constrain, I've just found this footnote on c standard: "A function declarator shall not specify a return type that is a function type or an array type." on page 118 https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1256.pdf

great work by the way, have a nice day!

paul-j-lucas commented 11 months ago

Why did you close it? It's still wrong.

paul-j-lucas commented 11 months ago

I tried a few obvious things, but none worked (without breaking other tests). It might take a while.

paul-j-lucas commented 10 months ago

The fix is kind of hack-ish. The code between adding functions and adding arrays is similar. I suspect that there's a more elegant fix waiting to be discovered that also unifies the code between arrays and functions.