-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C and CPP backends: use size_t for things such as sizes. #391
Conversation
Previously used `int` is not the return type of functions such as `strlen`, which generates compiler warnings.
I need to note that this probably didn't have any actual correctness impact, as it would require source files greater than 2**31 bytes. |
Thanks for the PR, @enedil!
What are these warnings and how do you trigger them? I am asking because I do not see these warnings. E.g., C backend:
C++ backend:
This is with
but I also do not see the warnings with the GNU compiler:
|
gcc -Wall perhaps counter-intuitively doesn't enable all warnings. For instance, there is also -Wextra which adds a bunch of additional warnings. I didn't test it on gcc however. On clang (which you seem to be really using, as on macOS gcc is usually an alias to clang), there is a flag -Weverything, and in particular, -Wshorten-64-to-32. |
Thanks. I tried
There is frequent If these are the warnings you care about, could you add them in the Makefile generation, so that the fruits of your PR are checked and preserved? |
I could add a bunch of those, but to be fair, the generated C++ code needs solid rework (as signaled by #293). I can add two flags and fix related warnings (in some quick way) though. What is the stance on slight change of interface? For instance, the PrintAbsyn returns a
instead of
|
Failed `new` will throw std::bad_alloc exception, thus it's not necessary (nor possible) to check the return value.
I tested the PR. The
So, the extra flag should not be added in the make-rule |
Ugh. On my grammar it didn't generate code with such warnings. Perhaps https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html ? We could push pragma to ignore these kind of errors when including files from flex? |
Reworking the C++ backend is most welcome. Atm, it has no active developer. (I am just fixing bugs.)
Not sure. Maybe because the code for the printer generator is shared between the C++(STL) and C++/NoSTL backends. Maybe we could retire the NoSTL backend. Or keep it while separating it from the STL backend, which then could freely use the STL.
I suppose I don't mind a modernization of the C++ backends (or just the STL one). Would you be interested in one and willing to work on it on a larger scale? |
There is grammars under There is also the testsuite under
This is indeed better than a second variable in the |
Disabling warnings as follows,
works for Thus, I tend to disable warnings in the Makefile as described in https://nelkinda.com/blog/suppress-warnings-in-gcc-and-clang/#w1223aab3b1c99. This seems to work: Lexer.o : CCFLAGS+=-Wno-sign-conversion
Lexer.o : Lexer.C Bison.H
${CC} ${CCFLAGS} -c Lexer.C |
I'm sorry I didn't have time to answer. Yes, you're correct that this kind of additional flags makes more sense. Does |
Good question. I don't know and cannot test this. In fact, I don't know if any of the |
According to https://godbolt.org/z/M1MTaqheE, |
Looking at https://www.fluentcpp.com/2019/08/30/how-to-disable-a-warning-in-cpp/ again, we are already in a non-portable state with the |
I agree |
I am doing the fixup and merge this now. Next time, please wider testing! |
Previously used `int` is not the return type of functions such as `strlen`, which generates compiler warnings. Coauthored by: Andreas Abel <andreas.abel@ifi.lmu.de>
Except for compiling the generated Lexer, where we switch it off again with -Wno-sign-conversion. Coauthored by: Andreas Abel <andreas.abel@ifi.lmu.de>
Failed `new` will throw std::bad_alloc exception, thus it's not necessary (nor possible) to check the return value.
Merged as:
|
Previously used
int
is not the return type of functions such asstrlen
, which generates compiler warnings.