Skip to content

Commit a5a4124

Browse files
committed
Revert [c++20] P1327R1: Support for typeid applied to objects of polymorphic class type in constant evaluation.
This reverts r360977 (git commit f51dc8d) llvm-svn: 360987
1 parent e18a6ad commit a5a4124

File tree

4 files changed

+20
-98
lines changed

4 files changed

+20
-98
lines changed

clang/include/clang/Basic/DiagnosticASTKinds.td

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ let Component = "AST" in {
1212
def note_expr_divide_by_zero : Note<"division by zero">;
1313
def note_constexpr_invalid_cast : Note<
1414
"%select{reinterpret_cast|dynamic_cast|cast that performs the conversions of"
15-
" a reinterpret_cast|cast from %1}0 is not allowed in a constant expression"
16-
"%select{| in C++ standards before C++2a||}0">;
15+
" a reinterpret_cast|cast from %1}0 is not allowed in a constant expression">;
1716
def note_constexpr_invalid_downcast : Note<
1817
"cannot cast object of dynamic type %0 to type %1">;
1918
def note_constexpr_overflow : Note<
@@ -32,13 +31,12 @@ def note_constexpr_invalid_inhctor : Note<
3231
def note_constexpr_no_return : Note<
3332
"control reached end of constexpr function">;
3433
def note_constexpr_virtual_call : Note<
35-
"cannot evaluate call to virtual function in a constant expression "
36-
"in C++ standards before C++2a">;
34+
"cannot evaluate call to virtual function in a constant expression">;
3735
def note_constexpr_pure_virtual_call : Note<
3836
"pure virtual function %q0 called">;
3937
def note_constexpr_polymorphic_unknown_dynamic_type : Note<
40-
"%select{||||virtual function called on|dynamic_cast applied to|"
41-
"typeid applied to}0 object '%1' whose dynamic type is not constant">;
38+
"%select{||||virtual function called on|dynamic_cast applied to}0 "
39+
"object '%1' whose dynamic type is not constant">;
4240
def note_constexpr_dynamic_cast_to_reference_failed : Note<
4341
"reference dynamic_cast failed: %select{"
4442
"static type %1 of operand is a non-public base class of dynamic type %2|"
@@ -92,7 +90,7 @@ def note_constexpr_var_init_non_constant : Note<
9290
"initializer of %0 is not a constant expression">;
9391
def note_constexpr_typeid_polymorphic : Note<
9492
"typeid applied to expression of polymorphic type %0 is "
95-
"not allowed in a constant expression in C++ standards before C++2a">;
93+
"not allowed in a constant expression">;
9694
def note_constexpr_void_comparison : Note<
9795
"comparison between unequal pointers to void has unspecified result">;
9896
def note_constexpr_temporary_here : Note<"temporary created here">;
@@ -110,11 +108,11 @@ def note_constexpr_this : Note<
110108
"evaluation of a call to a 'constexpr' member function">;
111109
def note_constexpr_lifetime_ended : Note<
112110
"%select{read of|assignment to|increment of|decrement of|member call on|"
113-
"dynamic_cast of|typeid applied to}0 "
111+
"dynamic_cast of}0 "
114112
"%select{temporary|variable}1 whose lifetime has ended">;
115113
def note_constexpr_access_uninit : Note<
116114
"%select{read of|assignment to|increment of|decrement of|member call on|"
117-
"dynamic_cast of|typeid applied to}0 "
115+
"dynamic_cast of}0 "
118116
"object outside its lifetime is not allowed in a constant expression">;
119117
def note_constexpr_use_uninit_reference : Note<
120118
"use of reference outside its lifetime "
@@ -141,30 +139,30 @@ def note_constexpr_ltor_incomplete_type : Note<
141139
"read of incomplete type %0 is not allowed in a constant expression">;
142140
def note_constexpr_access_null : Note<
143141
"%select{read of|assignment to|increment of|decrement of|member call on|"
144-
"dynamic_cast of|typeid applied to}0 "
142+
"dynamic_cast of}0 "
145143
"dereferenced null pointer is not allowed in a constant expression">;
146144
def note_constexpr_access_past_end : Note<
147145
"%select{read of|assignment to|increment of|decrement of|member call on|"
148-
"dynamic_cast of|typeid applied to}0 "
146+
"dynamic_cast of}0 "
149147
"dereferenced one-past-the-end pointer is not allowed in a constant expression">;
150148
def note_constexpr_access_unsized_array : Note<
151149
"%select{read of|assignment to|increment of|decrement of|member call on|"
152-
"dynamic_cast of|typeid applied to}0 "
150+
"dynamic_cast of}0 "
153151
"element of array without known bound "
154152
"is not allowed in a constant expression">;
155153
def note_constexpr_access_inactive_union_member : Note<
156154
"%select{read of|assignment to|increment of|decrement of|member call on|"
157-
"dynamic_cast of|typeid applied to}0 "
155+
"dynamic_cast of}0 "
158156
"member %1 of union with %select{active member %3|no active member}2 "
159157
"is not allowed in a constant expression">;
160158
def note_constexpr_access_static_temporary : Note<
161159
"%select{read of|assignment to|increment of|decrement of|member call on|"
162-
"dynamic_cast of|typeid applied to}0 temporary "
160+
"dynamic_cast of}0 temporary "
163161
"is not allowed in a constant expression outside the expression that "
164162
"created the temporary">;
165163
def note_constexpr_access_unreadable_object : Note<
166164
"%select{read of|assignment to|increment of|decrement of|member call on|"
167-
"dynamic_cast of|typeid applied to}0 object '%1' whose value is not known">;
165+
"dynamic_cast of}0 object '%1' whose value is not known">;
168166
def note_constexpr_modify_global : Note<
169167
"a constant expression cannot modify an object that is visible outside "
170168
"that expression">;

clang/lib/AST/ExprConstant.cpp

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,15 +1349,13 @@ enum AccessKinds {
13491349
AK_Decrement,
13501350
AK_MemberCall,
13511351
AK_DynamicCast,
1352-
AK_TypeId,
13531352
};
13541353

13551354
static bool isModification(AccessKinds AK) {
13561355
switch (AK) {
13571356
case AK_Read:
13581357
case AK_MemberCall:
13591358
case AK_DynamicCast:
1360-
case AK_TypeId:
13611359
return false;
13621360
case AK_Assign:
13631361
case AK_Increment:
@@ -6031,33 +6029,19 @@ LValueExprEvaluator::VisitCompoundLiteralExpr(const CompoundLiteralExpr *E) {
60316029
}
60326030

60336031
bool LValueExprEvaluator::VisitCXXTypeidExpr(const CXXTypeidExpr *E) {
6034-
TypeInfoLValue TypeInfo;
6035-
60366032
if (!E->isPotentiallyEvaluated()) {
6033+
TypeInfoLValue TypeInfo;
60376034
if (E->isTypeOperand())
60386035
TypeInfo = TypeInfoLValue(E->getTypeOperand(Info.Ctx).getTypePtr());
60396036
else
60406037
TypeInfo = TypeInfoLValue(E->getExprOperand()->getType().getTypePtr());
6041-
} else {
6042-
if (!Info.Ctx.getLangOpts().CPlusPlus2a) {
6043-
Info.CCEDiag(E, diag::note_constexpr_typeid_polymorphic)
6044-
<< E->getExprOperand()->getType()
6045-
<< E->getExprOperand()->getSourceRange();
6046-
}
6047-
6048-
if (!Visit(E->getExprOperand()))
6049-
return false;
6050-
6051-
Optional<DynamicType> DynType =
6052-
ComputeDynamicType(Info, E, Result, AK_TypeId);
6053-
if (!DynType)
6054-
return false;
6055-
6056-
TypeInfo =
6057-
TypeInfoLValue(Info.Ctx.getRecordType(DynType->Type).getTypePtr());
6038+
return Success(APValue::LValueBase::getTypeInfo(TypeInfo, E->getType()));
60586039
}
60596040

6060-
return Success(APValue::LValueBase::getTypeInfo(TypeInfo, E->getType()));
6041+
Info.FFDiag(E, diag::note_constexpr_typeid_polymorphic)
6042+
<< E->getExprOperand()->getType()
6043+
<< E->getExprOperand()->getSourceRange();
6044+
return false;
60616045
}
60626046

60636047
bool LValueExprEvaluator::VisitCXXUuidofExpr(const CXXUuidofExpr *E) {

clang/test/SemaCXX/constant-expression-cxx2a.cpp

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
#include "Inputs/std-compare.h"
44

5-
namespace std {
6-
struct type_info;
7-
};
8-
95
namespace ThreeWayComparison {
106
struct A {
117
int n;
@@ -358,58 +354,3 @@ namespace DynamicCast {
358354
// expected-note@+1 {{reference dynamic_cast failed: dynamic type 'DynamicCast::G' of operand does not have a base class of type 'DynamicCast::Unrelated'}}
359355
constexpr int e_unrelated = (dynamic_cast<Unrelated&>((E&)g), 0); // expected-error {{}}
360356
}
361-
362-
namespace TypeId {
363-
struct A {
364-
const std::type_info &ti = typeid(*this);
365-
};
366-
struct A2 : A {};
367-
static_assert(&A().ti == &typeid(A));
368-
static_assert(&typeid((A2())) == &typeid(A2));
369-
extern A2 extern_a2;
370-
static_assert(&typeid(extern_a2) == &typeid(A2));
371-
372-
constexpr A2 a2;
373-
constexpr const A &a1 = a2;
374-
static_assert(&typeid(a1) == &typeid(A));
375-
376-
struct B {
377-
virtual void f();
378-
const std::type_info &ti1 = typeid(*this);
379-
};
380-
struct B2 : B {
381-
const std::type_info &ti2 = typeid(*this);
382-
};
383-
static_assert(&B2().ti1 == &typeid(B));
384-
static_assert(&B2().ti2 == &typeid(B2));
385-
extern B2 extern_b2;
386-
// expected-note@+1 {{typeid applied to object 'extern_b2' whose dynamic type is not constant}}
387-
static_assert(&typeid(extern_b2) == &typeid(B2)); // expected-error {{constant expression}}
388-
389-
constexpr B2 b2;
390-
constexpr const B &b1 = b2;
391-
static_assert(&typeid(b1) == &typeid(B2));
392-
393-
constexpr bool side_effects() {
394-
// Not polymorphic nor a glvalue.
395-
bool OK = true;
396-
(void)typeid(OK = false, A2()); // expected-warning {{has no effect}}
397-
if (!OK) return false;
398-
399-
// Not polymorphic.
400-
A2 a2;
401-
(void)typeid(OK = false, a2); // expected-warning {{has no effect}}
402-
if (!OK) return false;
403-
404-
// Not a glvalue.
405-
(void)typeid(OK = false, B2()); // expected-warning {{has no effect}}
406-
if (!OK) return false;
407-
408-
// Polymorphic glvalue: operand evaluated.
409-
OK = false;
410-
B2 b2;
411-
(void)typeid(OK = true, b2); // expected-warning {{will be evaluated}}
412-
return OK;
413-
}
414-
static_assert(side_effects());
415-
}

clang/www/cxx_status.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -973,11 +973,10 @@ <h2 id="cxx20">C++2a implementation status</h2>
973973
</tr>
974974
<tr>
975975
<td><a href="http://wg21.link/p1327r1">P1327R1</a></td>
976-
<td class="svn" align="center">SVN</td>
976+
<td rowspan=2 class="none" align="center">No</td>
977977
</tr>
978978
<tr>
979979
<td><a href="http://wg21.link/p1330r0">P1330R0</a></td>
980-
<td class="none" align="center">No</td>
981980
</tr>
982981
<tr>
983982
<td>Prohibit aggregates with user-declared constructors</td>

0 commit comments

Comments
 (0)