Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flang/include/flang/Evaluate/complex.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ template <typename REAL_TYPE> class Complex {
im_.Compare(that.im_) == Relation::Equal;
}

constexpr bool IsZero() const { return re_.IsZero() || im_.IsZero(); }
constexpr bool IsZero() const { return re_.IsZero() && im_.IsZero(); }

constexpr bool IsInfinite() const {
return re_.IsInfinite() || im_.IsInfinite();
Expand Down
9 changes: 8 additions & 1 deletion flang/lib/Evaluate/fold-implementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -2156,7 +2156,14 @@ Expr<T> FoldOperation(FoldingContext &context, Power<T> &&x) {
}
return Expr<T>{Constant<T>{power.power}};
} else {
if (auto callable{GetHostRuntimeWrapper<T, T, T>("pow")}) {
if (folded->first.IsZero()) {
if (folded->second.IsZero()) {
context.messages().Say(common::UsageWarning::FoldingException,
"REAL/COMPLEX 0**0 is not defined"_warn_en_US);
} else {
return Expr<T>(Constant<T>{folded->first}); // 0. ** nonzero -> 0.
}
} else if (auto callable{GetHostRuntimeWrapper<T, T, T>("pow")}) {
return Expr<T>{
Constant<T>{(*callable)(context, folded->first, folded->second)}};
} else if (context.languageFeatures().ShouldWarn(
Expand Down
17 changes: 17 additions & 0 deletions flang/test/Semantics/bug1046.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
!WARNING: INTEGER(4) 0**0 is not defined
print *, 0**0
!WARNING: REAL/COMPLEX 0**0 is not defined
print *, 0**0.
!WARNING: invalid argument on power with INTEGER exponent
print *, 0.0**0
!WARNING: REAL/COMPLEX 0**0 is not defined
print *, 0.0**0.
!WARNING: invalid argument on power with INTEGER exponent
print *, (0.0, 0.0)**0
!WARNING: REAL/COMPLEX 0**0 is not defined
print *, (0.0, 0.0)**0.
print *, (0.0, 0.0)**2.5
end


Loading