diff --git a/flang/lib/Parser/program-parsers.cpp b/flang/lib/Parser/program-parsers.cpp index e365cd24a6aed..d6e7f11297187 100644 --- a/flang/lib/Parser/program-parsers.cpp +++ b/flang/lib/Parser/program-parsers.cpp @@ -64,7 +64,7 @@ static constexpr auto programUnit{ construct(indirect(subroutineSubprogram)) || construct(indirect(Parser{})) || construct(indirect(Parser{})) || - lookAhead(validFunctionStmt) >> + lookAhead(maybe(label) >> validFunctionStmt) >> construct(indirect(functionSubprogram)) || construct(indirect(Parser{}))}; static constexpr auto normalProgramUnit{StartNewSubprogram{} >> programUnit / diff --git a/flang/test/Parser/func-label.f b/flang/test/Parser/func-label.f new file mode 100644 index 0000000000000..d78545177f64e --- /dev/null +++ b/flang/test/Parser/func-label.f @@ -0,0 +1,7 @@ +! RUN: %flang_fc1 -fsyntax-only -pedantic %s 2>&1 | FileCheck --allow-empty %s +!CHECK-NOT: error: + 1 function fun() + 2 end function + 3 write(6,*) "pass" + 4 end +