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

[expr.typeid] glvalue of incomplete type vs typeid #4826

Closed
xmh0511 opened this issue Aug 19, 2021 · 4 comments · Fixed by #4827
Closed

[expr.typeid] glvalue of incomplete type vs typeid #4826

xmh0511 opened this issue Aug 19, 2021 · 4 comments · Fixed by #4827
Assignees
Labels
cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Aug 19, 2021

struct C;
int storage;
C* ptr = (C*)&storage;
typeid(*ptr);  //#1

All compilers report #1 is an error, with the diagnosis invalid use of incomplete type. However, there's no relevant rule in the standard that restricts the type of the glvalue operand in [expr.typeid]. Is it an omission?

@jwakely
Copy link
Member

jwakely commented Aug 19, 2021

Since it's unknown whether S is a polymorphic type or not, the behaviour here seems undefined. So giving an error is fine. Making it explicitly ill-formed would probably be better though.

@jensmaurer
Copy link
Member

dynamic_cast consistently requires complete types for both source and target.

We have "If the type of the type-id is a class type or a reference to a class type, the class shall be completely-defined."

It seems plausible that this rule should also apply to the "expression" case.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Aug 19, 2021

Maybe, we could say that

When typeid is applied to an expression, If the static type of the expression is a (possibly cv-qualified) class type, the class shall be completely-defined.

Which is before [expr.typeid] p2.

@xmh0511
Copy link
Contributor Author

xmh0511 commented Aug 19, 2021

@jensmaurer For [expr.typeid] p3

If the expression is a prvalue, the temporary materialization conversion is applied. The expression is an unevaluated operand.

How about the following case?

typeid(static_cast<void>(0));

The operand is a prvalue of type void as per [expr.static.cast] p1 and [expr.static.cast] p6, which means the temporary materialization conversion is not possible to be applied to that operand. It is a bit contradictory.

@jensmaurer jensmaurer self-assigned this Aug 19, 2021
@jensmaurer jensmaurer added cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking. labels Aug 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cwg Issue must be reviewed by CWG. not-editorial Issue is not deemed editorial; the editorial issue is kept open for tracking.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants