Skip to content

Commit eb77f44

Browse files
authored
[flang] Accept L0 (#121998)
Accept a zero field width for formatted logical output (L0), interpreting it as if it had been L1.
1 parent 9462ce8 commit eb77f44

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

flang/docs/Extensions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ end
410410
* A character length specifier in a component or entity declaration
411411
is accepted before an array specification (`ch*3(2)`) as well
412412
as afterwards.
413+
* A zero field width is allowed for logical formatted output (`L0`).
413414

414415
### Extensions supported when enabled by options
415416

flang/include/flang/Common/format.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,10 +463,13 @@ template <typename CHAR> void FormatValidator<CHAR>::check_r(bool allowed) {
463463
template <typename CHAR> bool FormatValidator<CHAR>::check_w() {
464464
if (token_.kind() == TokenKind::UnsignedInteger) {
465465
wValue_ = integerValue_;
466-
if (wValue_ == 0 &&
467-
(*argString_ == 'A' || *argString_ == 'L' ||
468-
stmt_ == IoStmtKind::Read)) { // C1306, 13.7.2.1p6
469-
ReportError("'%s' edit descriptor 'w' value must be positive");
466+
if (wValue_ == 0) {
467+
if (*argString_ == 'A' || stmt_ == IoStmtKind::Read) {
468+
// C1306, 13.7.2.1p6
469+
ReportError("'%s' edit descriptor 'w' value must be positive");
470+
} else if (*argString_ == 'L') {
471+
ReportWarning("'%s' edit descriptor 'w' value should be positive");
472+
}
470473
}
471474
NextToken();
472475
return true;

flang/test/Semantics/io07.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,10 @@
6868
6001 format(((I0, B0)))
6969

7070
!ERROR: 'A' edit descriptor 'w' value must be positive
71-
!ERROR: 'L' edit descriptor 'w' value must be positive
71+
!WARNING: 'L' edit descriptor 'w' value should be positive
7272
6101 format((A0), ((L0)))
7373

74-
!ERROR: 'L' edit descriptor 'w' value must be positive
74+
!WARNING: 'L' edit descriptor 'w' value should be positive
7575
6102 format((3(((L 0 0 0)))))
7676

7777
7001 format(17G8.1, 17G8.1e3)

flang/test/Semantics/io08.f90

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,7 @@
192192
!ERROR: 'A' edit descriptor 'w' value must be positive
193193
write(*,'(A0)')
194194

195-
!ERROR: 'L' edit descriptor 'w' value must be positive
196-
write(*,'(L0)')
195+
write(*,'(L0)') ! warning, not error
197196

198197
!ERROR: Expected 'G' edit descriptor '.d' value
199198
write(*,'(G4)')

flang/unittests/Runtime/LogicalFormatTest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ TEST(IOApiTests, LogicalFormatTest) {
2323
char buffer[bufferSize];
2424

2525
// Create format for all types and values to be written
26-
const char *format{"(L,L3,I3,L2,L2,I3,L2,A3,L2,L,F4.1,L2)"};
26+
const char *format{"(L0,L3,I3,L2,L2,I3,L2,A3,L2,L,F4.1,L2)"};
2727
auto cookie{IONAME(BeginInternalFormattedOutput)(
2828
buffer, bufferSize, format, std::strlen(format))};
2929

0 commit comments

Comments
 (0)