@@ -5012,6 +5012,20 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
5012
5012
return From;
5013
5013
}
5014
5014
5015
+ // / Checks that type T is not a VLA.
5016
+ // /
5017
+ // / @returns @c true if @p T is VLA and a diagnostic was emitted,
5018
+ // / @c false otherwise.
5019
+ static bool DiagnoseVLAInCXXTypeTrait (Sema &S, const TypeSourceInfo *T,
5020
+ clang::tok::TokenKind TypeTraitID) {
5021
+ if (!T->getType ()->isVariableArrayType ())
5022
+ return false ;
5023
+
5024
+ S.Diag (T->getTypeLoc ().getBeginLoc (), diag::err_vla_unsupported)
5025
+ << 1 << TypeTraitID;
5026
+ return true ;
5027
+ }
5028
+
5015
5029
// / Check the completeness of a type in a unary type trait.
5016
5030
// /
5017
5031
// / If the particular type trait requires a complete type, tries to complete
@@ -5188,7 +5202,9 @@ static bool HasNoThrowOperator(const RecordType *RT, OverloadedOperatorKind Op,
5188
5202
}
5189
5203
5190
5204
static bool EvaluateUnaryTypeTrait (Sema &Self, TypeTrait UTT,
5191
- SourceLocation KeyLoc, QualType T) {
5205
+ SourceLocation KeyLoc,
5206
+ TypeSourceInfo *TInfo) {
5207
+ QualType T = TInfo->getType ();
5192
5208
assert (!T->isDependentType () && " Cannot evaluate traits of dependent type" );
5193
5209
5194
5210
ASTContext &C = Self.Context ;
@@ -5205,21 +5221,13 @@ static bool EvaluateUnaryTypeTrait(Sema &Self, TypeTrait UTT,
5205
5221
case UTT_IsArray:
5206
5222
return T->isArrayType ();
5207
5223
case UTT_IsBoundedArray:
5208
- if (!T->isVariableArrayType ()) {
5209
- return T->isArrayType () && !T->isIncompleteArrayType ();
5210
- }
5211
-
5212
- Self.Diag (KeyLoc, diag::err_vla_unsupported)
5213
- << 1 << tok::kw___is_bounded_array;
5214
- return false ;
5224
+ if (DiagnoseVLAInCXXTypeTrait (Self, TInfo, tok::kw___is_bounded_array))
5225
+ return false ;
5226
+ return T->isArrayType () && !T->isIncompleteArrayType ();
5215
5227
case UTT_IsUnboundedArray:
5216
- if (!T->isVariableArrayType ()) {
5217
- return T->isIncompleteArrayType ();
5218
- }
5219
-
5220
- Self.Diag (KeyLoc, diag::err_vla_unsupported)
5221
- << 1 << tok::kw___is_unbounded_array;
5222
- return false ;
5228
+ if (DiagnoseVLAInCXXTypeTrait (Self, TInfo, tok::kw___is_unbounded_array))
5229
+ return false ;
5230
+ return T->isIncompleteArrayType ();
5223
5231
case UTT_IsPointer:
5224
5232
return T->isAnyPointerType ();
5225
5233
case UTT_IsNullPointer:
@@ -5631,7 +5639,7 @@ static bool EvaluateBooleanTypeTrait(Sema &S, TypeTrait Kind,
5631
5639
return false ;
5632
5640
5633
5641
if (Kind <= UTT_Last)
5634
- return EvaluateUnaryTypeTrait (S, Kind, KWLoc, Args[0 ]-> getType () );
5642
+ return EvaluateUnaryTypeTrait (S, Kind, KWLoc, Args[0 ]);
5635
5643
5636
5644
// Evaluate ReferenceBindsToTemporary and ReferenceConstructsFromTemporary
5637
5645
// alongside the IsConstructible traits to avoid duplication.
@@ -6093,12 +6101,9 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI
6093
6101
Self.RequireCompleteType (Rhs->getTypeLoc ().getBeginLoc (), RhsT,
6094
6102
diag::err_incomplete_type);
6095
6103
6096
- if (LhsT->isVariableArrayType ())
6097
- Self.Diag (Lhs->getTypeLoc ().getBeginLoc (), diag::err_vla_unsupported)
6098
- << 1 << tok::kw___is_layout_compatible;
6099
- if (RhsT->isVariableArrayType ())
6100
- Self.Diag (Rhs->getTypeLoc ().getBeginLoc (), diag::err_vla_unsupported)
6101
- << 1 << tok::kw___is_layout_compatible;
6104
+ DiagnoseVLAInCXXTypeTrait (Self, Lhs, tok::kw___is_layout_compatible);
6105
+ DiagnoseVLAInCXXTypeTrait (Self, Rhs, tok::kw___is_layout_compatible);
6106
+
6102
6107
return Self.IsLayoutCompatible (LhsT, RhsT);
6103
6108
}
6104
6109
case BTT_IsPointerInterconvertibleBaseOf: {
@@ -6108,12 +6113,10 @@ static bool EvaluateBinaryTypeTrait(Sema &Self, TypeTrait BTT, const TypeSourceI
6108
6113
diag::err_incomplete_type);
6109
6114
}
6110
6115
6111
- if (LhsT->isVariableArrayType ())
6112
- Self.Diag (Lhs->getTypeLoc ().getBeginLoc (), diag::err_vla_unsupported)
6113
- << 1 << tok::kw___is_pointer_interconvertible_base_of;
6114
- if (RhsT->isVariableArrayType ())
6115
- Self.Diag (Rhs->getTypeLoc ().getBeginLoc (), diag::err_vla_unsupported)
6116
- << 1 << tok::kw___is_pointer_interconvertible_base_of;
6116
+ DiagnoseVLAInCXXTypeTrait (Self, Lhs,
6117
+ tok::kw___is_pointer_interconvertible_base_of);
6118
+ DiagnoseVLAInCXXTypeTrait (Self, Rhs,
6119
+ tok::kw___is_pointer_interconvertible_base_of);
6117
6120
6118
6121
return Self.IsPointerInterconvertibleBaseOf (Lhs, Rhs);
6119
6122
}
0 commit comments