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

CWG2887 [diff.cpp03.expr] List behavioral changes of typeid and conditional operators in C++11 #528

Open
frederick-vs-ja opened this issue Apr 18, 2024 · 1 comment

Comments

@frederick-vs-ja
Copy link

frederick-vs-ja commented Apr 18, 2024

Full name of submitter (unless configured in github; will be published with the issue): Jiang An

Reference (section label): [diff.cpp03.expr]

Link to reflector thread (if any):

Issue description:

From editorial issue cplusplus/draft#6861.

N3055 distinguished xvalues from prvalues in typeid and ternary conditional operators, which changed their behaviors in some code that were well-formed in both C++98 and C++11.

  1. More expressions were made evaluated in typeid (demo). Such expressions are xvalues of polymorphic class types that were already well-formed in C++98.
#include <cstdio>
#include <typeinfo>

int main() {
  struct B {
    B() {}
    virtual ~B() { std::puts("C++11"); }
  };

  struct C { B b; };
  typeid(C().b); // unevaluated in C++98, evaluated in C++11
}
  1. Less copies were made in the conditional operator (demo) if the second and the third operands were xvalues (that were well-formed in C++98) and the result was also an xvalue since C++11.
#include <cstdio>

int main() {
  struct B {
    B() {}
    B(const B&) { std::puts("C++98"); }
  };
  struct D : B {};

  struct BB { B b; };
  struct DD { D d; };

  true ? BB().b : DD().d; // additional copy in C++98, no copy or move in C++11
}

Perhaps we should list the behavior changes in [diff.cpp03.expr].

Suggested resolution:

@jensmaurer jensmaurer changed the title [diff.cpp03.expr] List behavioral changes of typeid and conditional operators in C++11 CWG2887 [diff.cpp03.expr] List behavioral changes of typeid and conditional operators in C++11 Apr 29, 2024
@jensmaurer
Copy link
Member

CWG2887

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

No branches or pull requests

2 participants