← Back to Pull requests

Fix `empty_value` MSVC bug #175

Merged
k3DW merged 4 files (111 lines) on Jul 12, 2024 12:53 UTC
View on GitHub
k3DW k3DW commented on Jun 19, 2024 17:42 UTC
Author

See unordered#257.

Is this a breaking change in Core? It doesn't break any tests, but is it conceptually wrong?

Diff: 111 lines (+106 / -5) across 4 files Reviewer: Lastique Review duration: 32831m
All Vouch review confidence checks passed
Residual risk 0.03 = Change Risk (0.36) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 111 lines diff across 4 files
0.36
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.92 · 5 substantive comment(s)
0.92
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
90%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.282
Real PR Conversation Timeline
16 items
mglisse mglisse commented on Jun 22, 2024 10:26 UTC
Contributor

(thank you for working on this. Just a user's comments below)

Is this a breaking change in Core?

I think so. As broken as the permission model is in C++ (private things are traps instead of being invisible), there are still some cases where SFINAE can ignore private things, that work with the current code and would be broken with public inheritance.

is it conceptually wrong?

Again, I think so. It may still be worth it if the bug it works around is worse than what this breaks (I have no idea how to measure that), but if this change is done, in my opinion it should be protected by something like BOOST_WORKAROUND(BOOST_MSVC, ...) with a link to the bug report on Microsoft's website.

On recent compilers, a simpler implementation of empty_value based on (msvc::)no_unique_address could also be considered.

pdimov pdimov commented on Jun 22, 2024 16:31 UTC
Contributor

On recent compilers, a simpler implementation of empty_value based on (msvc::)no_unique_address could also be considered.

This sounds like the best course of action here.

k3DW k3DW commented on Jun 23, 2024 23:06 UTC
Author

> On recent compilers, a simpler implementation of empty_value based on (msvc::)no_unique_address could also be considered.

> This sounds like the best course of action here.

I'm not sure how far back this problem goes on MSVC. On 16.0, the oldest available version on Compiler Explorer right now, the issue reproduces.

That said, how would this be implemented using [[msvc::no_unique_address]]? Usages of empty_value rely on EBO, which is transitive through inheritance. Anything using NUA isn't transitive. CE link

I can't find any documentation for when [[msvc::no_unique_address]] was introduced. This attribute doesn't work in MSVC 16.8, but it starts working in MSVC 16.9. We need this fixed earlier than 16.8, so I don't think we can use NUA here.

pdimov pdimov commented on Jun 23, 2024 23:27 UTC
Contributor

[[no_unique_address]] works for the same example under Clang and GCC: https://godbolt.org/z/PzqreT8Eb
But we need it for MSVC, which is exactly where it doesn't. :-)

Lastique Lastique commented on Jun 24, 2024 00:02 UTC
Contributor

Was this bug reported to MSVC devs? If not, please do.

As to this PR, I think, this is a better workaround. [[no_unique_address]] is not worth it. And not the right way to go anyway, as compilers are allowed to ignore/not support attributes, while EBO is a requirement.

mglisse mglisse commented on Jun 24, 2024 06:48 UTC
Contributor

That said, how would this be implemented using [[msvc::no_unique_address]]? Usages of empty_value rely on EBO, which is transitive through inheritance. Anything using NUA isn't transitive. CE link

:exploding_head: The whole point of NUA is to replace EBO, and MSVC managed to fail...

Actually, msvc::no_unique_address is a failure, but there may still be a bit of hope for the real no_unique_address if we complain enough (report 1, report 2) before the next ABI break in MSVC :crossed_fingers:

Lastique Lastique commented on code on Jun 24, 2024 08:08 UTC
Code Review
include/boost/core/empty_value.hpp:1
@@ -95,9 +95,45 @@ class empty_value {
 };
 
 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
+template<class T>
+class empty_value_base

This class should be in namespace detail. And it should only be used #if defined(BOOST_MSVC), otherwise the previous implementation should be in effect.

Lastique Lastique commented on Jun 24, 2024 20:57 UTC
Contributor

Thanks. Looks ok to me.

k3DW k3DW commented on Jun 25, 2024 03:39 UTC
Author

Thanks. Looks ok to me.

Great thanks

Was this bug reported to MSVC devs? If not, please do.

Got it, here is the bug report. It seems like it's been around for a while, so I'm not holding out hope that it'll get fixed any time soon. But at least we were able to get a workaround

Lastique Lastique commented on Jun 25, 2024 08:15 UTC
Contributor

> Was this bug reported to MSVC devs? If not, please do.

> Got it, here is the bug report.

Please, add a short description and a link to the bug in a comment near #if defined(BOOST_MSVC) and the new test_derived_compile test.

It seems like it's been around for a while, so I'm not holding out hope that it'll get fixed any time soon.

If it's not been reported before, it is likely it wasn't known to the MSVC devs, which is why it wasn't fixed and why it needed to be reported. I don't expect it to be immediately fixed, but it will be, eventually.

joaquintides joaquintides commented on Jul 08, 2024 07:36 UTC
Contributor

Reminder that we should merge this fix before the Boost 1.86 release window closes. Thank you!

pdimov pdimov commented on Jul 08, 2024 07:39 UTC
Contributor

@glenfe ?

ashtum ashtum commented on Jul 13, 2024 08:44 UTC
Contributor

The following issue has arisen due to a conflict with the new private type alias base introduced recently:

``C++
#include <boost/core/empty_value.hpp>
#include <memory>

struct A : boost::empty_value<std::allocator<void>>
{
};

using base = A;

struct B : base
{
B()
: base{}
{
}
};



Error (active) E0265 type "boost::empty_::empty_value<T, N, true>::base [with T=std::allocator<void>, N=0U]" (declared at line 141 of "C:\Users\win\Desktop\boost\boost\core\empty_value.hpp") is inaccessible
``

pdimov pdimov commented on Jul 13, 2024 08:46 UTC
Contributor

This can be fixed by renaming empty_value<..>::base to something less likely to cause conflicts, such as e.g. core_ev_base.

ashtum ashtum commented on Jul 16, 2024 18:16 UTC
Contributor

https://github.com/boostorg/core/commit/242b14bb690ca7b4f924b6dd35f397a2779813a3 broke Boost.Beast again. I can rename the typedefs in Beast, but I guess base_type is quite a common name used by other users as well: https://github.com/boostorg/beast/blob/develop/test/beast/core/async_base.cpp#L677

Reviewers
Assignees
k3DW k3DW
Labels
risk: low confidence: 90.2% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 35.6% (MEDIUM) · Higher = larger blast radius
35.6%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 90.2% · Lower = rushed or shallow review
90.2%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 3.5% · Safe to merge
3.5%
Repository