Warum sind Mitglieder [[no_unique_address]] nicht transparent ersetzt?C++

Programme in C++. Entwicklerforum
Anonymous
 Warum sind Mitglieder [[no_unique_address]] nicht transparent ersetzt?

Post by Anonymous »

Im klassischen Talk an (in-) vollständige Anleitung zu C ++ Objektlebensdauer von Jonathan Müller gibt es eine nützliche Richtlinie wie folgt:

q: Wenn ich StDD: von:

[*] const Heap -Objekte,
[*] Basisklassen oder

Code: Select all

[[no_unique_address]]
Mitglieder.

Code: Select all

struct Empty {};

struct A {
[[no_unique_address]] Empty e = {};
char                        c = {};
};

int main() {
auto a  = A{};
auto p1 = &a;
auto p2 = new (p1) A{};
(void)p2->c; // OK.
(void)p2->e; // OK.
(void)p1->c; // OK.
(void)p1->e; // UB due to bullet 3.
}
Das UB ist ursprünglich auf diese c ++ Standardregel
o 2 if ... und weder o 1 noch o 2 ist ein potenzielles Subobjekt. sind:


Warum verhängt der C ++-Standard eine so spezielle Beschränkung für potenziell überlappende Subobjekte? />

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post