ldn-softdev / jtc

JSON processing utility
MIT License
501 stars 33 forks source link

Doesn't compile #1

Closed oguz-ismail closed 5 years ago

oguz-ismail commented 5 years ago

I've tried both GCC 7.3.0 (on Ubuntu 18.04.1) and Clang 7.0.0 (on Termux) but it doesn't compile, here is the output of Clang:

$ c++ -o jtc -Wall -std=c++14 -Ofast jtc.cpp
In file included from jtc.cpp:7:
./lib/getoptions.hpp:451:51: warning: result of comparison of constant -1 with expression of type 'char' is always true [-Wtautological-constant-out-of-range-compare]
 while((option = getopt(argc, argv, fmt.c_str())) != -1) {      // read next option character
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^  ~~
In file included from jtc.cpp:9:
./lib/shell.hpp:38:25: error: reference to function type cannot have 'const' qualifier
    const std::string & stdout(void) const { return out_; }
                        ^
/data/data/com.termux/files/usr/include/stdio.h:78:17: note: expanded from macro 'stdout'
#define stdout (&__sF[1])
                ^
In file included from jtc.cpp:9:
./lib/shell.hpp:35:50: error: use of undeclared identifier 'buf_'
                        Shell(size_t s = 1024) { buf_.resize(s); }
                                                 ^
./lib/shell.hpp:38:60: error: expected ';' after class
    const std::string & stdout(void) const { return out_; }
                                                           ^
                                                           ;
./lib/shell.hpp:39:34: error: non-member function cannot have 'const' qualifier
    int                 rc(void) const { return rc_; }
                                 ^~~~~~
./lib/shell.hpp:39:49: error: use of undeclared identifier 'rc_'; did you mean 'rc'?
    int                 rc(void) const { return rc_; }
                                                ^~~
                                                rc
./lib/shell.hpp:39:25: note: 'rc' declared here
    int                 rc(void) const { return rc_; }
                        ^
./lib/shell.hpp:40:41: error: non-member function cannot have 'const' qualifier
    size_t              buff_size(void) const { return buf_.size(); }
                                        ^~~~~~
./lib/shell.hpp:40:56: error: use of undeclared identifier 'buf_'
    size_t              buff_size(void) const { return buf_.size(); }
                                                       ^
./lib/shell.hpp:41:47: error: use of undeclared identifier 'buf_'
    Shell &             buff_size(size_t s) { buf_.resize(s); return *this; }
                                              ^
./lib/shell.hpp:41:71: error: invalid use of 'this' outside of a non-static member function
    Shell &             buff_size(size_t s) { buf_.resize(s); return *this; }
                                                                      ^
./lib/shell.hpp:45:2: error: expected unqualified-id
 protected:
 ^
./lib/shell.hpp:49:2: error: expected unqualified-id
 private:
 ^
./lib/shell.hpp:52:16: error: unknown type name 'ThrowReason'
    EXCEPTIONS(ThrowReason)                                     // see "enums.hpp"
               ^
./lib/shell.hpp:52:5: error: non-member function cannot have 'const' qualifier
    EXCEPTIONS(ThrowReason)                                     // see "enums.hpp"
    ^
./lib/extensions.hpp:143:91: note: expanded from macro 'EXCEPTIONS'
    stdException __exp__(THROW_ENUM reason, const char *func, const char *file, int line) const \
                                                                                          ^
In file included from jtc.cpp:9:
./lib/shell.hpp:52:5: error: use of undeclared identifier 'ThrowReason_str'
./lib/extensions.hpp:144:39: note: expanded from macro 'EXCEPTIONS'
        { return stdException{reason, ENUMS(THROW_ENUM, reason), func, file, line}; }
                                      ^
./lib/extensions.hpp:65:37: note: expanded from macro 'ENUMS'
#define ENUMS(enum_class, enum_idx) enum_class ## _str[enum_idx]
                                    ^
<scratch space>:132:1: note: expanded from here
ThrowReason_str
^
In file included from jtc.cpp:9:
./lib/shell.hpp:53:1: error: extraneous closing brace ('}')
};
^
./lib/shell.hpp:64:2: error: use of undeclared identifier 'out_'
 out_.clear();
 ^
./lib/shell.hpp:68:14: error: use of undeclared identifier 'buf_'
 while(fgets(buf_.data(), buf_.size(), fh) != nullptr)
             ^
./lib/shell.hpp:68:27: error: use of undeclared identifier 'buf_'
 while(fgets(buf_.data(), buf_.size(), fh) != nullptr)
                          ^
./lib/shell.hpp:69:3: error: use of undeclared identifier 'out_'
  out_ += buf_.data();
  ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
1 warning and 20 errors generated.
ldn-softdev commented 5 years ago

Could you try using compilation line for linux (the above will only work for MacOS): $ c++ -o jtc -Wall -std=gnu++14 -static -Ofast jtc.cpp

Let me know if it works for you, I'll also update the compile instructions

oguz-ismail commented 5 years ago

It works with both GCC and Clang on Ubuntu, thanks. Clang on Termux still gives the same errors, but I think this issue is related to Termux.

ldn-softdev commented 5 years ago

it's definitely the problem with the compiler under Termux, b/c errors like:

./lib/shell.hpp:38:25: error: reference to function type cannot have 'const' qualifier const std::string & stdout(void) const { return out_; }

tell that the complier mistakenly "thinks" that a class method (here stdout()) is a function type, which hints that the compiler does not operate in terms of c++.