@@ -209,10 +209,12 @@ template <typename TO, TypeCategory FROMCAT = TO::category>
209209struct Convert : public Operation <Convert<TO, FROMCAT>, TO, SomeKind<FROMCAT>> {
210210 // Fortran doesn't have conversions between kinds of CHARACTER apart from
211211 // assignments, and in those the data must be convertible to/from 7-bit ASCII.
212- static_assert (((TO::category == TypeCategory::Integer ||
213- TO::category == TypeCategory::Real) &&
214- (FROMCAT == TypeCategory::Integer ||
215- FROMCAT == TypeCategory::Real)) ||
212+ static_assert (
213+ ((TO::category == TypeCategory::Integer ||
214+ TO::category == TypeCategory::Real ||
215+ TO::category == TypeCategory::Unsigned) &&
216+ (FROMCAT == TypeCategory::Integer || FROMCAT == TypeCategory::Real ||
217+ FROMCAT == TypeCategory::Unsigned)) ||
216218 TO::category == FROMCAT);
217219 using Result = TO;
218220 using Operand = SomeKind<FROMCAT>;
@@ -526,7 +528,8 @@ class Expr<Type<TypeCategory::Integer, KIND>>
526528
527529private:
528530 using Conversions = std::tuple<Convert<Result, TypeCategory::Integer>,
529- Convert<Result, TypeCategory::Real>>;
531+ Convert<Result, TypeCategory::Real>,
532+ Convert<Result, TypeCategory::Unsigned>>;
530533 using Operations = std::tuple<Parentheses<Result>, Negate<Result>,
531534 Add<Result>, Subtract<Result>, Multiply<Result>, Divide<Result>,
532535 Power<Result>, Extremum<Result>>;
@@ -547,6 +550,29 @@ class Expr<Type<TypeCategory::Integer, KIND>>
547550 u;
548551};
549552
553+ template <int KIND>
554+ class Expr <Type<TypeCategory::Unsigned, KIND>>
555+ : public ExpressionBase<Type<TypeCategory::Unsigned, KIND>> {
556+ public:
557+ using Result = Type<TypeCategory::Unsigned, KIND>;
558+
559+ EVALUATE_UNION_CLASS_BOILERPLATE (Expr)
560+
561+ private:
562+ using Conversions = std::tuple<Convert<Result, TypeCategory::Integer>,
563+ Convert<Result, TypeCategory::Real>,
564+ Convert<Result, TypeCategory::Unsigned>>;
565+ using Operations =
566+ std::tuple<Parentheses<Result>, Negate<Result>, Add<Result>,
567+ Subtract<Result>, Multiply<Result>, Divide<Result>, Extremum<Result>>;
568+ using Others = std::tuple<Constant<Result>, ArrayConstructor<Result>,
569+ Designator<Result>, FunctionRef<Result>>;
570+
571+ public:
572+ common::TupleToVariant<common::CombineTuples<Operations, Conversions, Others>>
573+ u;
574+ };
575+
550576template <int KIND>
551577class Expr <Type<TypeCategory::Real, KIND>>
552578 : public ExpressionBase<Type<TypeCategory::Real, KIND>> {
@@ -560,7 +586,8 @@ class Expr<Type<TypeCategory::Real, KIND>>
560586 // N.B. Real->Complex and Complex->Real conversions are done with CMPLX
561587 // and part access operations (resp.).
562588 using Conversions = std::variant<Convert<Result, TypeCategory::Integer>,
563- Convert<Result, TypeCategory::Real>>;
589+ Convert<Result, TypeCategory::Real>,
590+ Convert<Result, TypeCategory::Unsigned>>;
564591 using Operations = std::variant<ComplexComponent<KIND>, Parentheses<Result>,
565592 Negate<Result>, Add<Result>, Subtract<Result>, Multiply<Result>,
566593 Divide<Result>, Power<Result>, RealToIntPower<Result>, Extremum<Result>>;
@@ -590,6 +617,7 @@ class Expr<Type<TypeCategory::Complex, KIND>>
590617};
591618
592619FOR_EACH_INTEGER_KIND (extern template class Expr , )
620+ FOR_EACH_UNSIGNED_KIND (extern template class Expr , )
593621FOR_EACH_REAL_KIND (extern template class Expr , )
594622FOR_EACH_COMPLEX_KIND (extern template class Expr , )
595623
@@ -629,7 +657,8 @@ class Relational : public Operation<Relational<T>, LogicalResult, T, T> {
629657 static_assert (Operand::category == TypeCategory::Integer ||
630658 Operand::category == TypeCategory::Real ||
631659 Operand::category == TypeCategory::Complex ||
632- Operand::category == TypeCategory::Character);
660+ Operand::category == TypeCategory::Character ||
661+ Operand::category == TypeCategory::Unsigned);
633662 CLASS_BOILERPLATE (Relational)
634663 Relational (
635664 RelationalOperator r, const Expr<Operand> &a, const Expr<Operand> &b)
@@ -642,7 +671,7 @@ class Relational : public Operation<Relational<T>, LogicalResult, T, T> {
642671
643672template <> class Relational <SomeType> {
644673 using DirectlyComparableTypes = common::CombineTuples<IntegerTypes, RealTypes,
645- ComplexTypes, CharacterTypes>;
674+ ComplexTypes, CharacterTypes, UnsignedTypes >;
646675
647676public:
648677 using Result = LogicalResult;
@@ -656,6 +685,7 @@ template <> class Relational<SomeType> {
656685};
657686
658687FOR_EACH_INTEGER_KIND (extern template class Relational , )
688+ FOR_EACH_UNSIGNED_KIND (extern template class Relational , )
659689FOR_EACH_REAL_KIND (extern template class Relational , )
660690FOR_EACH_CHARACTER_KIND (extern template class Relational , )
661691extern template class Relational <SomeType>;
@@ -886,6 +916,7 @@ FOR_EACH_INTRINSIC_KIND(extern template class ArrayConstructor, )
886916 FOR_EACH_INTRINSIC_KIND (template class Expr , ) \
887917 FOR_EACH_CATEGORY_TYPE (template class Expr , ) \
888918 FOR_EACH_INTEGER_KIND (template class Relational , ) \
919+ FOR_EACH_UNSIGNED_KIND (template class Relational , ) \
889920 FOR_EACH_REAL_KIND (template class Relational , ) \
890921 FOR_EACH_CHARACTER_KIND (template class Relational , ) \
891922 template class Relational <SomeType>; \
0 commit comments