Skip to content

Replace nullptr with empty string in ternary expressions - #351

Merged
nikolaygorb merged 1 commit into
openvinotoolkit:developfrom
oToToT:fix/ie-nullptr-to-string-cxx23
Oct 9, 2026
Merged

nikolaygorb merged 1 commit into
openvinotoolkit:developfrom
oToToT:fix/ie-nullptr-to-string-cxx23

Conversation

@oToToT

@oToToT oToToT commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Problem:
In C++23 (P2166R1 - A Proposal to Prohibit std::basic_string and std::basic_string_view construction from nullptr), constructing a std::string from nullptr is explicitly deleted:
basic_string(nullptr_t) = delete;

In optimize_precision_across_function_calls.cpp, ternary logging expressions evaluate:
(producerCallOp != nullptr) ? producerCallOp->getName().getStringRef().str() : nullptr

Under C++23, the common type of std::string and std::nullptr_t cannot be deduced because std::string(nullptr) is deleted, causing:
error: non-constant-expression cannot be narrowed from type 'nullptr_t' to 'std::string'

Even prior to C++23, passing nullptr to basic_string is an undefined behavior per P2166R1. Hence, regardless of C++23, we should fix it.

Solution:
Replace : nullptr with an empty string literal : "" in both ternary expressions.

JIRA ticket

N/A

Target Platform For Release Notes

Aids the generation of release notes

  • NPU37XX
  • NPU40XX
  • NPU50XX
  • NONE (Not included in release notes)

Classification of this Pull Request

  • Maintenance
  • BUG
  • Feature

Related PRs

N/A

@oToToT
oToToT requested a review from a team as a code owner September 17, 2026 11:14
@Maxim-Doronin

Copy link
Copy Markdown
Collaborator

@oToToT sorry for bothering you again with this matter...
image

could you please sign&push again?

Problem:
In C++23 (P2166R1 - A Proposal to Prohibit std::basic_string and
std::basic_string_view construction from nullptr), constructing
a std::string from nullptr is explicitly deleted:
  basic_string(nullptr_t) = delete;

In `optimize_precision_across_function_calls.cpp`, ternary logging
expressions evaluate:
  (producerCallOp != nullptr) ? producerCallOp->getName().getStringRef().str() : nullptr

Under C++23, the common type of `std::string` and `std::nullptr_t` cannot
be deduced because `std::string(nullptr)` is deleted, causing:
  error: non-constant-expression cannot be narrowed from type 'nullptr_t' to 'std::string'

Even prior to C++23, passing nullptr to basic_string is an undefined
behavior per P2166R1. Hence, regardless of C++23, we should fix it.

Solution:
Replace `: nullptr` with an empty string literal `: ""` in both ternary expressions.
@oToToT
oToToT force-pushed the fix/ie-nullptr-to-string-cxx23 branch from 919894a to 1ab6202 Compare October 9, 2026 12:22
@oToToT

oToToT commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

done. sorry didn't aware of this at the time I create this PR.

@nikolaygorb
nikolaygorb enabled auto-merge (squash) October 9, 2026 12:35
@nikolaygorb
nikolaygorb merged commit d70915d into openvinotoolkit:develop Oct 9, 2026
22 checks passed
@oToToT
oToToT deleted the fix/ie-nullptr-to-string-cxx23 branch October 9, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants