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/Support/Fortran-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ ENUM_CLASS(UsageWarning, Portability, PointerToUndefinable,
ZeroDoStep, UnusedForallIndex, OpenMPUsage, DataLength, IgnoredDirective,
HomonymousSpecific, HomonymousResult, IgnoredIntrinsicFunctionType,
PreviousScalarUse, RedeclaredInaccessibleComponent, ImplicitShared,
IndexVarRedefinition, IncompatibleImplicitInterfaces,
IndexVarRedefinition, IncompatibleImplicitInterfaces, CdefinedInit,
VectorSubscriptFinalization, UndefinedFunctionResult, UselessIomsg,
MismatchingDummyProcedure, SubscriptedEmptyArray, UnsignedLiteralTruncation,
CompatibleDeclarationsFromDistinctModules,
Expand Down
3 changes: 3 additions & 0 deletions flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9118,6 +9118,9 @@ void DeclarationVisitor::NonPointerInitialization(
if (details->init()) {
SayWithDecl(name, *name.symbol,
"'%s' has already been initialized"_err_en_US);
} else if (details->isCDefined()) {
context().Warn(common::UsageWarning::CdefinedInit, name.source,
"CDEFINED variable should not have an initializer"_warn_en_US);
} else if (IsAllocatable(ultimate)) {
Say(name, "Allocatable object '%s' cannot be initialized"_err_en_US);
} else if (ultimate.owner().IsParameterizedDerivedType()) {
Expand Down
6 changes: 6 additions & 0 deletions flang/test/Semantics/cdefined.f90
Original file line number Diff line number Diff line change
@@ -0,0 +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]
integer(c_int), bind(C, name='c_global', CDEFINED) :: c = 42
end