Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9194,11 +9194,12 @@ bool DeclarationVisitor::CheckNonPointerInitialization(
"'%s' has already been initialized"_err_en_US);
} else if (IsAllocatable(ultimate)) {
Say(name, "Allocatable object '%s' cannot be initialized"_err_en_US);
} else if (details->isCDefined()) {
// CDEFINED variables cannot have initializer, because their storage
// may come outside of Fortran.
context().Warn(common::UsageWarning::CdefinedInit, name.source,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they can't be initialized, this should be a hard error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

"CDEFINED variable cannot be initialized"_warn_en_US);
} else {
if (details->isCDefined()) {
context().Warn(common::UsageWarning::CdefinedInit, name.source,
"CDEFINED variable should not have an initializer"_warn_en_US);
}
return true;
}
} else {
Expand Down
1 change: 1 addition & 0 deletions flang/test/Lower/cdefined.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ module m
integer(c_int), bind(C, name='c_global', CDEFINED) :: c = 42
! CHECK: fir.global @c_global : i32
! CHECK-NOT: fir.zero_bits
! CHECK-NOT: arith.constant 42
end
2 changes: 1 addition & 1 deletion flang/test/Semantics/cdefined.f90
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic -Werror
module m
use iso_c_binding
!WARNING: CDEFINED variable should not have an initializer [-Wcdefined-init]
!WARNING: CDEFINED variable cannot be initialized [-Wcdefined-init]
integer(c_int), bind(C, name='c_global', CDEFINED) :: c = 42
end