[flang-commits] [flang] 7d147a3 - [flang] Warn on missing colons (C768)
Peter Klausler via flang-commits
flang-commits at lists.llvm.org
Sat Dec 3 09:27:51 PST 2022
Author: Peter Klausler
Date: 2022-12-03T09:27:39-08:00
New Revision: 7d147a326331374e0af4d1d76a1cfb7faa8df0ad
URL: https://github.com/llvm/llvm-project/commit/7d147a326331374e0af4d1d76a1cfb7faa8df0ad
DIFF: https://github.com/llvm/llvm-project/commit/7d147a326331374e0af4d1d76a1cfb7faa8df0ad.diff
LOG: [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
Added:
flang/test/Parser/missing-colons.f90
Modified:
flang/docs/Extensions.md
flang/lib/Parser/Fortran-parsers.cpp
Removed:
################################################################################
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md
index a512048293f20..e56585e60149b 100644
--- a/flang/docs/Extensions.md
+++ b/flang/docs/Extensions.md
@@ -242,6 +242,11 @@ end
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
diff --git a/flang/lib/Parser/Fortran-parsers.cpp b/flang/lib/Parser/Fortran-parsers.cpp
index 86c3d55e5c1c6..5f64d3346d7e4 100644
--- a/flang/lib/Parser/Fortran-parsers.cpp
+++ b/flang/lib/Parser/Fortran-parsers.cpp
@@ -522,6 +522,9 @@ TYPE_CONTEXT_PARSER("type bound procedure binding"_en_US,
// 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 @@ TYPE_CONTEXT_PARSER("type bound PROCEDURE statement"_en_US,
"," >> 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>{}),
diff --git a/flang/test/Parser/missing-colons.f90 b/flang/test/Parser/missing-colons.f90
new file mode 100644
index 0000000000000..ebb728cf0810c
--- /dev/null
+++ b/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
+
More information about the flang-commits
mailing list