fuzziqersoftware / phosg

C++ helpers for some common tasks
18 stars 17 forks source link

Fix compilation on Alpine Linux micro-distro #32

Closed eleriaqueen closed 10 months ago

eleriaqueen commented 10 months ago

Alpine Linux is often used in Docker containers.

I'm using these dependencies : git cmake build-base gdb zlib-dev libevent-dev gnu-libiconv-dev ca-certificates linux-headers bash netcat-openbsd python3 procps

With the fix I'm able to compile phosg in an Alpine Linux container and compilation on a "regular" Arch based system still works. Without the fix there's and issue where compiler can't find definition of nullptr_t.

/newserv/phosg # make -j 8
[  2%] Building CXX object CMakeFiles/phosg.dir/src/JSON.cc.o
In file included from /newserv/phosg/src/JSON.cc:1:
/newserv/phosg/src/JSON.hh:27:67: error: 'nullptr_t' was not declared in this scope; did you mean 'std::nullptr_t'?
   27 |   inline static constexpr bool is_primitive_v = std::is_same_v<T, nullptr_t> || std::is_integral_v<T> || std::is_floating_point_v<T> || std::is_same_v<T, bool> || std::is_same_v<T, std::string>;
      |                                                                   ^~~~~~~~~
      |                                                                   std::nullptr_t
In file included from /usr/include/c++/12.2.1/type_traits:38,
                 from /usr/include/c++/12.2.1/concepts:44,
                 from /usr/include/c++/12.2.1/compare:39,
                 from /newserv/phosg/src/JSON.hh:3:
/usr/include/c++/12.2.1/x86_64-alpine-linux-musl/bits/c++config.h:302:33: note: 'std::nullptr_t' declared here
  302 |   typedef decltype(nullptr)     nullptr_t;
      |                                 ^~~~~~~~~
/newserv/phosg/src/JSON.hh:87:7: error: unnecessary parentheses in declaration of 'nullptr_t' [-Werror=parentheses]
   87 |   JSON(nullptr_t);
      |       ^~~~~~~~~~~
/newserv/phosg/src/JSON.hh:87:7: note: remove parentheses
   87 |   JSON(nullptr_t);
      |       ^~~~~~~~~~~
      |       -         -
/newserv/phosg/src/JSON.hh:87:8: error: field 'nullptr_t' has incomplete type 'JSON'
   87 |   JSON(nullptr_t);
      |        ^~~~~~~~~
/newserv/phosg/src/JSON.hh:18:7: note: definition of 'class JSON' is not complete until the closing brace
   18 | class JSON {
      |       ^~~~
/newserv/phosg/src/JSON.hh:163:37: error: 'nullptr_t' is not a type
  163 |   std::partial_ordering operator<=>(nullptr_t) const; // Same as is_null()
      |                                     ^~~~~~~~~
/newserv/phosg/src/JSON.hh:458:7: error: invalid use of non-static data member 'JSON::nullptr_t'
  458 |       nullptr_t, // We use this type for JSON null
      |       ^~~~~~~~~
/newserv/phosg/src/JSON.hh:87:8: note: declared here
   87 |   JSON(nullptr_t);
      |        ^~~~~~~~~
/newserv/phosg/src/JSON.hh:464:16: error: template argument 1 is invalid
  464 |       dict_type>
      |                ^
fuzziqersoftware commented 10 months ago

Unfortunately, we shouldn't use using namespace statements in header files - this would cause any other file that includes this header to implicitly use that namespace, which can lead to subtle bugs in other programs. It would be better to change all uses of nullptr_t in this file to std::nullptr_t instead.

eleriaqueen commented 10 months ago

I updated the fix according to your observations.

fuzziqersoftware commented 10 months ago

Thanks for fixing this!