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

Usage with -fno-elide-constructors causes dump() output to be array of nulls #2387

Closed
Qix- opened this issue Sep 5, 2020 · 2 comments · Fixed by #2405
Closed

Usage with -fno-elide-constructors causes dump() output to be array of nulls #2387

Qix- opened this issue Sep 5, 2020 · 2 comments · Fixed by #2405
Assignees
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@Qix-
Copy link

Qix- commented Sep 5, 2020

What is the issue you have?

The following program...

#include "./json.hpp"

#include <iostream>

nlohmann::json makeobj() {
        return {
                {"type", "Foo"},
                {"location", {10, 20}}
        };
}

int main() {
        std::cout << makeobj().dump() << std::endl;
        return 0;
}

... compiled with the following flags ...

$ c++ -Wall -Wextra -Werror -std=c++11 -Wshadow -pedantic-errors -fno-elide-constructors -Winit-self -Wold-style-cast -Woverloaded-virtual -Wuninitialized -Wmissing-declarations -fvisibility=hidde
n -Wunused -g3 -O0 -otest-json test-json.cc

... produces the following output:

[[null,null],[null,[null,null]]]

Omitting the -fno-elide-constructors flag, we get the following (correct) output:

{"location":[10,20],"type":"Foo"}

I've since removed the -fno-elide-constructors from the build script as it was leftover from another project and isn't necessary (or really a good idea) for this project. I just figured you might want to know about it.

I don't fully understand the nuances of the flag but I would imagine it's not a flag that'd be "compatible" with this library (understandably so). At the very least, some documentation in the Notes section in the readme might be a worthwhile PR as it was the first place I looked for an explanation of the null output. Caused a 15 minute headache tracking it down - not terrible, but just annoying enough to open this issue :)

Thanks for the great library!

Which compiler and operating system are you using?

$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS"

$ c++ --version
Ubuntu clang version 12.0.0-++20200829052612+bf21ce7b908-1~exp1~20200829153238.148
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin

Which version of the library did you use?

Commit 1bcabd9; single include header vendored into project.

@stale
Copy link

stale bot commented Oct 12, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Oct 12, 2020
@Qix-
Copy link
Author

Qix- commented Oct 12, 2020

Ugh I hate this bot, don't bother. I'll close it for you.

@Qix- Qix- closed this as completed Oct 12, 2020
@nlohmann nlohmann reopened this Dec 11, 2020
@stale stale bot removed the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Dec 11, 2020
@nlohmann nlohmann self-assigned this Dec 11, 2020
@nlohmann nlohmann added release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Dec 11, 2020
@nlohmann nlohmann added this to the Release 3.9.2 milestone Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants