[flang] C774: Defined operator/assignment may not have NOPASS

Original-commit: flang-compiler/f18@6bfa3d3568
Reviewed-on: https://github.com/flang-compiler/f18/pull/872
Tree-same-pre-rewrite: false
This commit is contained in:
Tim Keith 2019-12-13 16:22:48 -08:00
parent e567bf9f5e
commit 6e2e78a09e
3 changed files with 19 additions and 2 deletions

View File

@ -518,7 +518,9 @@ static bool ConflictsWithIntrinsicOperator(
bool CheckHelper::CheckDefinedOperator(const SourceName &opName,
const GenericKind &kind, const Symbol &specific, const Procedure &proc) {
std::optional<parser::MessageFixedText> msg;
if (!proc.functionResult.has_value()) {
if (specific.attrs().test(Attr::NOPASS)) { // C774
msg = "%s procedure '%s' may not have NOPASS attribute"_err_en_US;
} else if (!proc.functionResult.has_value()) {
msg = "%s procedure '%s' must be a function"_err_en_US;
} else if (proc.functionResult->IsAssumedLengthCharacter()) {
msg = "%s function '%s' may not have assumed-length CHARACTER(*)"
@ -608,7 +610,10 @@ bool CheckHelper::CheckDefinedOperatorArg(const SourceName &opName,
bool CheckHelper::CheckDefinedAssignment(
const Symbol &specific, const Procedure &proc) {
std::optional<parser::MessageFixedText> msg;
if (!proc.IsSubroutine()) {
if (specific.attrs().test(Attr::NOPASS)) { // C774
msg = "Defined assignment procedure '%s' may not have"
" NOPASS attribute"_err_en_US;
} else if (!proc.IsSubroutine()) {
msg = "Defined assignment procedure '%s' must be a subroutine"_err_en_US;
} else if (proc.dummyArguments.size() != 2) {
msg = "Defined assignment subroutine '%s' must have"

View File

@ -220,6 +220,12 @@ module m6
procedure, pass(y) :: p2 => f2
generic :: operator(+) => p2
end type
type :: t3
contains
procedure, nopass :: p1 => f1
!ERROR: OPERATOR(+) procedure 'p1' may not have NOPASS attribute
generic :: operator(+) => p1
end type
contains
integer function f1(x, y)
class(t1), intent(in) :: x

View File

@ -30,6 +30,12 @@ module m1
generic :: assignment(=) => assign_t, assign_t2, assign_t3, assign_t4
procedure :: assign_t4
end type
type :: t2
contains
procedure, nopass :: assign_t
!ERROR: Defined assignment procedure 'assign_t' may not have NOPASS attribute
generic :: assignment(=) => assign_t
end type
contains
subroutine assign_t(x, y)
class(t), intent(out) :: x