Skip to content

Conversation

@yichunk
Copy link
Contributor

@yichunk yichunk commented Jul 10, 2025

The nullptr cause Test failed: basic_string: construction from null is not valid.

The root cause is the ternary operator of std::string and nullptr

Before C++23:
Constructing a std::string from a null pointer (like nullptr or NULL) results in Undefined Behavior. This means the program's behavior is unpredictable and can lead to crashes or incorrect results.
In C++23 and later:
Constructing a std::string from a null pointer is explicitly disabled and will result in a compilation error. This prevents the undefined behavior from occurring.

https://softwareengineering.stackexchange.com/questions/450335/is-it-bad-practice-to-use-nullptr-in-ternary-operation

Change to use empty json j_null instead.
https://json.nlohmann.me/api/basic_json/is_null/

Tests pass with ./scripts/tests.sh

The nullptr cause `Test failed: basic_string: construction from null is not valid`.
Change to use json j_null instead.

Tests pass with `./scripts/tests.sh`
@yichunk yichunk requested review from yatarkan July 10, 2025 21:14
@yichunk
Copy link
Contributor Author

yichunk commented Jul 10, 2025

@ochafik for review

@ochafik ochafik merged commit 264eab4 into google:main Jul 11, 2025
3 of 11 checks passed
@yichunk yichunk deleted the fix_non_null branch July 11, 2025 17:10
ochafik pushed a commit to ochafik/minja that referenced this pull request Nov 2, 2025
The nullptr cause `Test failed: basic_string: construction from null is not valid`.
Change to use json j_null instead.

Tests pass with `./scripts/tests.sh`
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.

3 participants