Skip to content

Commit 7d147a3

Browse files
committed
[flang] Warn on missing colons (C768)
In a derived type definition, a type bound procedure declaration statement with neither interface nor attributes is required by constraint C768 to have the optional "::" between the PROCEDURE keyword and the bindings if any binding has a renaming with "=>". The colons are not actually necessary for a correct and unambiguous parse, so emit a warning when they are missing. Differential Revision: https://reviews.llvm.org/D139065
1 parent 16a72a0 commit 7d147a3

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

flang/docs/Extensions.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ end
242242
compilers, so it is not supported.
243243
* f18 doesn't impose a limit on the number of continuation lines
244244
allowed for a single statement.
245+
* When a type-bound procedure declaration statement has neither interface
246+
nor attributes, the "::" before the bindings is optional, even
247+
if a binding has renaming with "=> proc".
248+
The colons are not necessary for an unambiguous parse, C768
249+
notwithstanding.
245250

246251
### Extensions supported when enabled by options
247252

flang/lib/Parser/Fortran-parsers.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,9 @@ TYPE_CONTEXT_PARSER("type bound procedure binding"_en_US,
522522
// R749 type-bound-procedure-stmt ->
523523
// PROCEDURE [[, bind-attr-list] ::] type-bound-proc-decl-list |
524524
// PROCEDURE ( interface-name ) , bind-attr-list :: binding-name-list
525+
// The "::" is required by the standard (C768) in the first production if
526+
// any type-bound-proc-decl has a "=>', but it's not strictly necessary to
527+
// avoid a bad parse.
525528
TYPE_CONTEXT_PARSER("type bound PROCEDURE statement"_en_US,
526529
"PROCEDURE" >>
527530
(construct<TypeBoundProcedureStmt>(
@@ -531,6 +534,15 @@ TYPE_CONTEXT_PARSER("type bound PROCEDURE statement"_en_US,
531534
"," >> nonemptyList(Parser<BindAttr>{}), ok),
532535
localRecovery("expected list of binding names"_err_en_US,
533536
"::" >> listOfNames, SkipTo<'\n'>{}))) ||
537+
construct<TypeBoundProcedureStmt>(construct<
538+
TypeBoundProcedureStmt::WithoutInterface>(
539+
pure<std::list<BindAttr>>(),
540+
nonemptyList(
541+
"expected type bound procedure declarations"_err_en_US,
542+
construct<TypeBoundProcDecl>(name,
543+
maybe(extension<LanguageFeature::MissingColons>(
544+
"type-bound procedure statement should have '::' if it has '=>'"_port_en_US,
545+
"=>" >> name)))))) ||
534546
construct<TypeBoundProcedureStmt>(
535547
construct<TypeBoundProcedureStmt::WithoutInterface>(
536548
optionalListBeforeColons(Parser<BindAttr>{}),

flang/test/Parser/missing-colons.f90

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
! RUN: %flang_fc1 -fsyntax-only -pedantic %s 2>&1 | FileCheck %s
2+
module m
3+
type t
4+
contains
5+
!CHECK: portability: type-bound procedure statement should have '::' if it has '=>'
6+
procedure p => sub
7+
end type
8+
contains
9+
subroutine sub(x)
10+
class(t), intent(in) :: x
11+
end subroutine
12+
end module
13+

0 commit comments

Comments
 (0)