[flang-commits] [PATCH] D139065: [flang] Warn on missing colons (C768)
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Wed Nov 30 17:06:51 PST 2022
klausler created this revision.
klausler added a reviewer: vdonaldson.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a reviewer: sscalpone.
Herald added a project: All.
klausler requested review of this revision.
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.
https://reviews.llvm.org/D139065
Files:
flang/docs/Extensions.md
flang/lib/Parser/Fortran-parsers.cpp
flang/test/Parser/missing-colons.f90
Index: flang/test/Parser/missing-colons.f90
===================================================================
--- /dev/null
+++ flang/test/Parser/missing-colons.f90
@@ -0,0 +1,13 @@
+! RUN: %flang_fc1 -fsyntax-only -pedantic %s 2>&1 | FileCheck %s
+module m
+ type t
+ contains
+!CHECK: portability: type-bound procedure statement should have '::' if it has '=>'
+ procedure p => sub
+ end type
+ contains
+ subroutine sub(x)
+ class(t), intent(in) :: x
+ end subroutine
+end module
+
Index: flang/lib/Parser/Fortran-parsers.cpp
===================================================================
--- flang/lib/Parser/Fortran-parsers.cpp
+++ flang/lib/Parser/Fortran-parsers.cpp
@@ -522,6 +522,9 @@
// R749 type-bound-procedure-stmt ->
// PROCEDURE [[, bind-attr-list] ::] type-bound-proc-decl-list |
// PROCEDURE ( interface-name ) , bind-attr-list :: binding-name-list
+// The "::" is required by the standard (C768) in the first production if
+// any type-bound-proc-decl has a "=>', but it's not strictly necessary to
+// avoid a bad parse.
TYPE_CONTEXT_PARSER("type bound PROCEDURE statement"_en_US,
"PROCEDURE" >>
(construct<TypeBoundProcedureStmt>(
@@ -531,6 +534,15 @@
"," >> nonemptyList(Parser<BindAttr>{}), ok),
localRecovery("expected list of binding names"_err_en_US,
"::" >> listOfNames, SkipTo<'\n'>{}))) ||
+ construct<TypeBoundProcedureStmt>(construct<
+ TypeBoundProcedureStmt::WithoutInterface>(
+ pure<std::list<BindAttr>>(),
+ nonemptyList(
+ "expected type bound procedure declarations"_err_en_US,
+ construct<TypeBoundProcDecl>(name,
+ maybe(extension<LanguageFeature::MissingColons>(
+ "type-bound procedure statement should have '::' if it has '=>'"_port_en_US,
+ "=>" >> name)))))) ||
construct<TypeBoundProcedureStmt>(
construct<TypeBoundProcedureStmt::WithoutInterface>(
optionalListBeforeColons(Parser<BindAttr>{}),
Index: flang/docs/Extensions.md
===================================================================
--- flang/docs/Extensions.md
+++ flang/docs/Extensions.md
@@ -240,6 +240,13 @@
* The legacy extension intrinsic functions `IZEXT` and `JZEXT`
are supported; `ZEXT` has different behavior with various older
compilers, so it is not supported.
+* f18 doesn't impose a limit on the number of continuation lines
+ allowed for a single statement.
+* When a type-bound procedure declaration statement has neither interface
+ nor attributes, the "::" before the bindings is optional, even
+ if a binding has renaming with "=> proc".
+ The colons are not necessary for an unambiguous parse, C768
+ notwithstanding.
### Extensions supported when enabled by options
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139065.479110.patch
Type: text/x-patch
Size: 2947 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20221201/3a8bc5a7/attachment.bin>
More information about the flang-commits
mailing list