Skip to content
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

fut C++ build warnings #96

Closed
ghost opened this issue Aug 18, 2023 · 11 comments
Closed

fut C++ build warnings #96

ghost opened this issue Aug 18, 2023 · 11 comments
Assignees
Labels
bug Something isn't working

Comments

@ghost
Copy link

ghost commented Aug 18, 2023

This will get rid of these warnings:

libfut.cpp: In member function 'std::shared_ptr<FuExpr> FuSema::visitInterpolatedString(std::shared_ptr<FuInterpolatedString>)':
libfut.cpp:4055:45: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<FuInterpolatedPart>::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
 4055 |         for (int partsIndex = 0; partsIndex < expr->parts.size(); partsIndex++) {
      |                                  ~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
libfut.cpp: In member function 'std::shared_ptr<FuExpr> FuSema::resolveCallWithArguments(std::shared_ptr<FuCallExpr>, const std::vector<std::shared_ptr<FuExpr> >*)':
libfut.cpp:5282:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::shared_ptr<FuExpr> >::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
 5282 |                 if (i >= arguments->size()) {
      |                     ~~^~~~~~~~~~~~~~~~~~~~
libfut.cpp:5299:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::shared_ptr<FuExpr> >::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
 5299 |         if (i < arguments->size())
      |             ~~^~~~~~~~~~~~~~~~~~~
libfut.cpp:5313:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::shared_ptr<FuExpr> >::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
 5313 |                         if (i < arguments->size())
      |                             ~~^~~~~~~~~~~~~~~~~~~
libfut.cpp: In member function 'std::shared_ptr<FuExpr> FuSema::visitCallExpr(std::shared_ptr<FuCallExpr>)':
libfut.cpp:5342:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::shared_ptr<FuExpr> >::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
 5342 |                 for (int i = 0; i < arguments->size(); i++) {
      |                                 ~~^~~~~~~~~~~~~~~~~~~
libfut.cpp: In member function 'std::shared_ptr<FuExpr> FuSema::visitExpr(std::shared_ptr<FuExpr>)':
libfut.cpp:5400:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::shared_ptr<FuExpr> >::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
 5400 |                 for (int i = 0; i < items->size(); i++)
      |                                 ~~^~~~~~~~~~~~~~~
libfut.cpp: In member function 'void FuSema::visitSwitch(FuSwitch*)':
libfut.cpp:5834:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::shared_ptr<FuExpr> >::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
 5834 |                 for (int i = 0; i < kase.values.size(); i++) {
      |                                 ~~^~~~~~~~~~~~~~~~~~~~
libfut.cpp: In member function 'void GenBase::writeCoercedLiterals(const FuType*, const std::vector<std::shared_ptr<FuExpr> >*)':
libfut.cpp:6834:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::shared_ptr<FuExpr> >::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
 6834 |         for (int i = 0; i < exprs->size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~
libfut.cpp: In member function 'void GenC::writeArgsAndRightParenthesis(const FuMethod*, const std::vector<std::shared_ptr<FuExpr> >*)':
libfut.cpp:10158:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::shared_ptr<FuExpr> >::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
10158 |                 if (i >= args->size())
      |                     ~~^~~~~~~~~~~~~~~
libfut.cpp: In member function 'void GenD::writeInsertedArg(const FuType*, const std::vector<std::shared_ptr<FuExpr> >*, int)':
libfut.cpp:15660:26: warning: comparison of integer expressions of different signedness: 'std::vector<std::shared_ptr<FuExpr> >::size_type' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
15660 |         if (args->size() <= index) {
      |             ~~~~~~~~~~~~~^~~~~~~~
libfut.cpp: In member function 'void GenJsNoModule::writeInterpolatedLiteral(std::string_view)':
libfut.cpp:17904:48: warning: comparison of integer expressions of different signedness: 'int' and 'std::basic_string_view<char>::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
17904 |                 if (c == '`' || (c == '$' && i < s.length() && s[i] == '{'))
      |                                              ~~^~~~~~~~~~~~
libfut.cpp: In member function 'void GenSwift::initVarsAtIndent()':
libfut.cpp:20706:42: warning: comparison of integer expressions of different signedness: 'std::vector<std::unordered_set<std::basic_string_view<char> > >::size_type' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
20706 |         while (this->varsAtIndent.size() <= this->indent) {
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~
libfut.cpp: In member function 'virtual void GenSwift::visitSwitch(const FuSwitch*)':
libfut.cpp:20972:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::shared_ptr<FuExpr> >::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
20972 |                 for (int i = 0; i < kase.values.size(); i++) {
      |                                 ~~^~~~~~~~~~~~~~~~~~~~
@pfusik
Copy link
Collaborator

pfusik commented Aug 18, 2023

What do you mean by "use size_t" ? Introduce the size_t type in Fusion? Or emit type casts?

@ghost
Copy link
Author

ghost commented Aug 18, 2023

What do you mean by "use size_t" ? Introduce the size_t type in Fusion? Or emit type casts?

Use size_t in the generated code instead of int. As you can see, you are currently use int.

@pfusik
Copy link
Collaborator

pfusik commented Aug 18, 2023

Transpiling all ints to size_t is not an option. size_t is an unsigned type.

@pfusik pfusik self-assigned this Aug 18, 2023
@ghost
Copy link
Author

ghost commented Aug 18, 2023

Transpiling all ints to size_t is not an option. size_t is an unsigned type.

No. I didn't tell you to replace all instances of int with size_t. This is nonsense. I don't know where you got this idea because I have never said it. But size_t should be used for indexes (please read the warnings I posted on this thread) and something related to size like klass->typeParameterCount and arrayStg->length on #97.

@ghost
Copy link
Author

ghost commented Aug 18, 2023

Oh my bad. If the original Fusion code uses int then the transpiler just translated them as is. This is the expected behavior.

@ghost ghost closed this as not planned Won't fix, can't repro, duplicate, stale Aug 18, 2023
@ghost
Copy link
Author

ghost commented Aug 18, 2023

@pfusik Which language is Fusion written in? I'm confused. Is it written in itself or in C++?

@ghost ghost reopened this Aug 18, 2023
@pfusik
Copy link
Collaborator

pfusik commented Aug 18, 2023

Fusion is self-hosted. It transpiles itself to C++, C# and JavaScript.

I'd like to avoid the C++ compilation warnings, but haven't decided yet how.

@ghost
Copy link
Author

ghost commented Aug 18, 2023

Fusion is self-hosted. It transpiles itself to C++, C# and JavaScript.

I'd like to avoid the C++ compilation warnings, but haven't decided yet how.

Done 😄

#99

@pfusik pfusik mentioned this issue Aug 18, 2023
@pfusik
Copy link
Collaborator

pfusik commented Aug 18, 2023

I don't want to hide the warnings.

One option is emitting std::ssize, unfortunately that's C++20. Shall we cast to ptrdiff_t instead?

@BenBE
Copy link

BenBE commented Aug 18, 2023

ssize_t (in stddef.h) has been around for quite some time.

(I know that's not proper, canonical C++ in the purist sense, could use cstddef instead, but not sure re namespacing on those).

Edit: Ah, oops. Misread that. You could just implement ssize in the boilerplate used by Fusion in this case as seen in https://en.cppreference.com/w/cpp/iterator/size -> The implementation is not that difficult.

template <class C>
constexpr auto ssize(const C& c) -> std::common_type_t<std::ptrdiff_t, std::make_signed_t<decltype(c.size())>>
{
    using R = std::common_type_t<std::ptrdiff_t, std::make_signed_t<decltype(c.size())>>;
    return static_cast<R>(c.size());
}

pfusik added a commit that referenced this issue Aug 18, 2023
@pfusik
Copy link
Collaborator

pfusik commented Aug 18, 2023

I chose std::ssize. Compilers have been supporting it for some time and fut requires a C++20 compiler anyway. I know many projects are still not yet on C++20, but that's only a matter of time.

What's left is string length:

libfut.cpp: In member function 'void GenJsNoModule::writeInterpolatedLiteral(std::string_view)':
libfut.cpp:17904:48: warning: comparison of integer expressions of different signedness: 'int' and 
 'std::basic_string_view<char>::size_type' {aka 'long long unsigned int'} [-Wsign-compare]
  17904 |                 if (c == '`' || (c == '$' && i < s.length() && s[i] == '{'))
        |                                              ~~^~~~~~~~~~~~

@pfusik pfusik changed the title Use size_t instead of int for indexes fut C++ build warnings Aug 18, 2023
@pfusik pfusik added the bug Something isn't working label Aug 18, 2023
@pfusik pfusik closed this as completed in eb4fc12 Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants