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

Cannot compile: error: ‘this’ pointer is null #344

Closed
1 task done
g3n35i5 opened this issue Dec 15, 2021 · 2 comments
Closed
1 task done

Cannot compile: error: ‘this’ pointer is null #344

g3n35i5 opened this issue Dec 15, 2021 · 2 comments

Comments

@g3n35i5
Copy link

g3n35i5 commented Dec 15, 2021

Describe the bug

Expected behavior: jsoncons compiles without errors.

Actual behavior: I'm getting the following error:

/tmp/jsoncons/tests/src/json_traits_macro_functional_tests.cpp: In static member function ‘static jsoncons::json_type_traits<Json, {anonymous}::ns::Employee_NCGN>::value_type jsoncons::json_type_traits<Json, {anonymous}::ns::Employee_NCGN>::as(const Json&)’:
/tmp/jsoncons/include/jsoncons/json_traits_macros.hpp:530:172: error: ‘this’ pointer is null [-Werror=nonnull]
  530 | #define JSONCONS_CTOR_GETTER_NAME_AS_LAST_2(Getter, Name) (ajson.contains(Name)) ? (ajson.at(Name)).template as<typename std::decay<decltype(((value_type*)nullptr)->Getter())>::type>() : typename std::decay<decltype(((value_type*)nullptr)->Getter())>::type()
      |                                                                                                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~

Enumerate the steps to reproduce the bug

cd /tmp
git clone https://github.com/danielaparker/jsoncons.git
cd jsoncons
git checkout v0.168.1
mkdir build && cd build
cmake ..
make

What compiler, architecture, and operating system?

  • Compiler: g++
  • Architecture: x64
  • Operating system: Archlinux

What jsoncons library version?

  • Latest release 0.168.1
@g3n35i5 g3n35i5 added the Bug label Dec 15, 2021
@danielaparker
Copy link
Owner

It appears that with the -Werror=nonnull compiler option, your compiler doesn't like to see

(value_type*)nullptr

inside a decltype specifier. I added the -Werror=nonnull option for our g++ builds, but wasn't able to reproduce this issue on any of our test environments.

While not being able to reproduce it, I changed (value_type*)nullptr to std::declval<value_type*>(), which may satisfy your compiler. Would you be able to repeat your test with the code on master, and report back with the results?

@g3n35i5
Copy link
Author

g3n35i5 commented Dec 16, 2021

@danielaparker works perfectly, thank you for that quick solution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants