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

Fix compilation on Alpine Linux micro-distro #32

Merged
merged 1 commit into from
Dec 4, 2023

Conversation

eleriaqueen
Copy link
Contributor

@eleriaqueen eleriaqueen commented Dec 3, 2023

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
Copy link
Owner

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.

Replace nullptr_t with std::nullptr_t
@eleriaqueen
Copy link
Contributor Author

I updated the fix according to your observations.

@fuzziqersoftware
Copy link
Owner

Thanks for fixing this!

@fuzziqersoftware fuzziqersoftware merged commit 8b90286 into fuzziqersoftware:master Dec 4, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants