diff --git a/flang/lib/Semantics/check-declarations.cpp b/flang/lib/Semantics/check-declarations.cpp index a2f2906af10b8..c726be82eb313 100644 --- a/flang/lib/Semantics/check-declarations.cpp +++ b/flang/lib/Semantics/check-declarations.cpp @@ -66,6 +66,7 @@ class CheckHelper { void CheckVolatile(const Symbol &, const DerivedTypeSpec *); void CheckContiguous(const Symbol &); void CheckPointer(const Symbol &); + void CheckExternalAttrConflicts(const Symbol &); void CheckPassArg( const Symbol &proc, const Symbol *interface, const WithPassArg &); void CheckProcBinding(const Symbol &, const ProcBindingDetails &); @@ -696,6 +697,8 @@ void CheckHelper::CheckObjectEntity( CheckConflicting(symbol, Attr::SAVE, Attr::PARAMETER); CheckConflicting(symbol, Attr::TARGET, Attr::PARAMETER); CheckConflicting(symbol, Attr::VOLATILE, Attr::PARAMETER); + CheckConflicting(symbol, Attr::EXTERNAL, Attr::PARAMETER); + CheckConflicting(symbol, Attr::INTRINSIC, Attr::PARAMETER); Check(details.shape()); Check(details.coshape()); if (details.shape().Rank() > common::maxRank) { @@ -983,6 +986,7 @@ void CheckHelper::CheckObjectEntity( } } if (symbol.attrs().test(Attr::EXTERNAL)) { + CheckExternalAttrConflicts(symbol); SayWithDeclaration(symbol, "'%s' is a data object and may not be EXTERNAL"_err_en_US, symbol.name()); @@ -2460,6 +2464,10 @@ void CheckHelper::CheckPointer(const Symbol &symbol) { // C852 } } +void CheckHelper::CheckExternalAttrConflicts(const Symbol &symbol) { + CheckConflicting(symbol, Attr::EXTERNAL, Attr::INTRINSIC); // F'2023 C842 +} + // C760 constraints on the passed-object dummy argument // C757 constraints on procedure pointer components void CheckHelper::CheckPassArg( diff --git a/flang/test/Semantics/declarations02.f90 b/flang/test/Semantics/declarations02.f90 index 32c3517d13cd1..90f29f90d9d0e 100644 --- a/flang/test/Semantics/declarations02.f90 +++ b/flang/test/Semantics/declarations02.f90 @@ -24,6 +24,9 @@ module m target x4 volatile x4 + !ERROR: 'sin' may not have both the INTRINSIC and PARAMETER attributes + real, parameter, intrinsic :: sin + type :: my_type1 integer :: x4 end type diff --git a/flang/test/Semantics/declarations09.f90 b/flang/test/Semantics/declarations09.f90 new file mode 100644 index 0000000000000..8abe320f5d2f3 --- /dev/null +++ b/flang/test/Semantics/declarations09.f90 @@ -0,0 +1,11 @@ +! RUN: %python %S/test_errors.py %s %flang_fc1 -pedantic + +subroutine bug149771 + + !ERROR: 'exp' may not have both the EXTERNAL and INTRINSIC attributes + real, external, intrinsic :: exp + + !ERROR: 'x2' may not have both the EXTERNAL and PARAMETER attributes + integer, external, parameter :: x2 + +end subroutine bug149771