diff options
author | Peter Klausler <pklausler@nvidia.com> | 2023-07-20 10:39:04 -0700 |
---|---|---|
committer | Peter Klausler <pklausler@nvidia.com> | 2023-07-21 14:30:40 -0700 |
commit | 28eec1bd85d2a0eb342fbad8fb2cace389e772d5 (patch) | |
tree | 5b387277fe2a690d7ff0481766385dfb29afceb0 | |
parent | 290a98c7b00899b6aba0fc892e8f29fecc00a82e (diff) | |
download | llvm-28eec1bd85d2a0eb342fbad8fb2cace389e772d5.zip llvm-28eec1bd85d2a0eb342fbad8fb2cace389e772d5.tar.gz llvm-28eec1bd85d2a0eb342fbad8fb2cace389e772d5.tar.bz2 |
[flang] Portability warning and documentation for an obscure extension
A quotation mark can appear in a Fortran character literal by doubling
it; for example, PRINT *, "'""'" prints '"'. When those doubled
quotation marks are split by a free form line continuation, the
continuation line should have an ampersand before the second quotation
mark. But most compilers, including this one, allow the second
quotation mark to appear as the first character on the continuation
line, too.
So this works:
print *, "'"&
"'"
but it really should be written as:
print *, "'"&
&"'"
Emit a portability warning and document that we support this near-universal
extension.
Differential Revision: https://reviews.llvm.org/D155973
-rw-r--r-- | flang/docs/Extensions.md | 5 | ||||
-rw-r--r-- | flang/lib/Parser/prescan.cpp | 5 | ||||
-rw-r--r-- | flang/test/Parser/continuation-before-quote.f90 | 10 |
3 files changed, 20 insertions, 0 deletions
diff --git a/flang/docs/Extensions.md b/flang/docs/Extensions.md index 5938ecc..4646e0b 100644 --- a/flang/docs/Extensions.md +++ b/flang/docs/Extensions.md @@ -291,6 +291,10 @@ end numeric character literal kind prefix on the file name. * Intrinsic procedures TAND and ATAND. Constant folding is currently not supported for these procedures but this is planned. +* When a pair of quotation marks in a character literal are split + by a line continuation in free form, the second quotation mark + may appear at the beginning of the continuation line without an + ampersand, althought one is required by the standard. ### Extensions supported when enabled by options @@ -607,3 +611,4 @@ end module * `ENCODING=` is not in the list of changeable modes on an I/O unit, but every Fortran compiler allows the encoding to be changed on an open unit. + diff --git a/flang/lib/Parser/prescan.cpp b/flang/lib/Parser/prescan.cpp index 09b31b1..d84b62cb 100644 --- a/flang/lib/Parser/prescan.cpp +++ b/flang/lib/Parser/prescan.cpp @@ -726,6 +726,11 @@ void Prescanner::QuotedCharacterLiteral( break; } inCharLiteral_ = true; + if (insertASpace_) { + Say(GetProvenanceRange(at_, end), + "Repeated quote mark in character literal continuation line should have been preceded by '&'"_port_en_US); + insertASpace_ = false; + } } } inCharLiteral_ = false; diff --git a/flang/test/Parser/continuation-before-quote.f90 b/flang/test/Parser/continuation-before-quote.f90 new file mode 100644 index 0000000..4ae669f --- /dev/null +++ b/flang/test/Parser/continuation-before-quote.f90 @@ -0,0 +1,10 @@ +! RUN: %flang_fc1 -fsyntax-only %s 2>&1 | FileCheck %s +! Continuation between repeated quotation marks +subroutine test +!CHECK: portability: Repeated quote mark in character literal continuation line should have been preceded by '&' + print *, 'needs an '& +'ampersand''' +!CHECK-NOT: portability: Repeated quote mark in character literal continuation line should have been preceded by '&' + print *, 'has an '& +&'ampersand''' +end |